黄瓜'之后'胡克不工作?
我有一个DriverFactory类,它执行下面列出的设置等,但是一旦执行了所有步骤,' Cucumber After'方法dosnt似乎工作在DriverFactory中?
我想要一个主要的钩子课程'之前' '后'等等将停止步骤文件中的代码重复
public class DriverFactory {
protected WebDriver driver;
protected BasePage basePage;
protected LoginPage loginPage;
public WebDriver getDriver() {
if(driver == null) {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\src\\test\\java\\resources\\other\\chromedriver.exe");
this.driver = new ChromeDriver();
this.driver.manage().window().maximize();
this.driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
}
return this.driver;
}
public WebDriver returnDriver() {
return this.driver;
}
@After
public void test() throws Throwable {
this.driver.close();
this.driver.quit();
}
}
public class LoginSteps {
DriverFactory driverFactory = new DriverFactory();
WebDriver driver = driverFactory.getDriver();
@Given("^User navigates to the \"([^\"]*)\" website$")
public void user_navigates_to_the_website(String url) throws Throwable {
BasePage basePage = new BasePage(driver);
basePage.loadUrl(url);
}
@And("^User entered the \"([^\"]*)\" username$")
public void user_entered_the_username(String username) throws Throwable {
LoginPage loginPage = new LoginPage(driver);
loginPage.setUsername(username);
}
答案 0 :(得分:1)
答案 1 :(得分:0)
我遇到了同样的问题-我的@Before钩子起作用了,但是我的@After钩子却没有起作用。原来这是由于一个简单的导入问题引起的-可能是由于Intellij向我提供了导入列表时选择了错误的选项所致。我选择了junit.After类,而不是Cucumber.api.Java.After类:
import cucumber.api.java.Before;
import cucumber.api.java8.En;
import org.junit.After;
import org.openqa.selenium.By;