Merge pull request #8573 from Maiklins/BAEL-3590-fix-cucumber-hooks-tests

BAEL-3590 Fix Cucumber Hooks Integration Tests
This commit is contained in:
Eric Martin 2020-01-25 11:41:30 -06:00 committed by GitHub
commit 0dd24e4e5d
2 changed files with 49 additions and 43 deletions

View File

@ -0,0 +1,48 @@
package com.baeldung.cucumberhooks.books;
import io.cucumber.core.api.Scenario;
import io.cucumber.java.After;
import io.cucumber.java.AfterStep;
import io.cucumber.java.Before;
import io.cucumber.java.BeforeStep;
import io.cucumber.java8.En;
public class BookStoreWithHooksIntegrationHooks implements En {
public BookStoreWithHooksIntegrationHooks() {
Before(1, () -> startBrowser());
}
@Before(order=2, value="@Screenshots")
public void beforeScenario(Scenario scenario) {
takeScreenshot();
}
@After
public void afterScenario(Scenario scenario) {
takeScreenshot();
}
@BeforeStep
public void beforeStep(Scenario scenario) {
takeScreenshot();
}
@AfterStep
public void afterStep(Scenario scenario) {
takeScreenshot();
closeBrowser();
}
public void takeScreenshot() {
//code to take and save screenshot
}
public void startBrowser() {
//code to open browser
}
public void closeBrowser() {
//code to close browser
}
}

View File

@ -1,11 +1,5 @@
package com.baeldung.cucumberhooks.books;
import io.cucumber.core.api.Scenario;
import io.cucumber.java.After;
import io.cucumber.java.AfterStep;
import io.cucumber.java.Before;
import io.cucumber.java.BeforeStep;
import io.cucumber.java8.En;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
@ -14,42 +8,6 @@ import org.junit.runner.RunWith;
@CucumberOptions(features = "classpath:features/book-store-with-hooks.feature",
glue = "com.baeldung.cucumberhooks.books"
)
public class BookStoreWithHooksIntegrationTest implements En {
public class BookStoreWithHooksIntegrationTest {
public BookStoreWithHooksIntegrationTest() {
Before(1, () -> startBrowser());
}
@Before(order=2, value="@Screenshots")
public void beforeScenario(Scenario scenario) {
takeScreenshot();
}
@After
public void afterScenario(Scenario scenario) {
takeScreenshot();
}
@BeforeStep
public void beforeStep(Scenario scenario) {
takeScreenshot();
}
@AfterStep
public void afterStep(Scenario scenario) {
takeScreenshot();
closeBrowser();
}
public void takeScreenshot() {
//code to take and save screenshot
}
public void startBrowser() {
//code to open browser
}
public void closeBrowser() {
//code to close browser
}
}