public class MS848Steps {
WebDriver driver;
@Given("Website is live and available")
public void website_is_live_and_available() {
System.out.println("Website is live and available!");
}
@When("Website works on Firefox")
public void website_works_on_firefox() {
driver = new FirefoxDriver();
driver.get("https://demowebshop.tricentis.com/");
System.out.println("Website works on Firefox!");
}
@And("Website works on Chrome")
public void website_works_on_chrome() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
driver = new ChromeDriver(options);
driver.get("https://demowebshop.tricentis.com/");
System.out.println("Website works on Chrome!");
}
@And("Website works on Edge")
public void website_works_on_edge() {
driver = new EdgeDriver();
driver.get("https://demowebshop.tricentis.com/");
System.out.println("Website works on Edge!");
}
@Then("Website works on every browser")
public void website_works_on_every_browser() {
System.out.println("Website works on every Browsers!");
}
@After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
如果我执行下面的代码,Chrome和Firefox浏览器仍然打开。我还尝试把一个驱动程序。和驱动程序.quit();在每个浏览器打开之后。但是没有任何帮助。甚至ChatGBT也帮不了我。
1条答案
按热度按时间htzpubme1#
问题是你为所有三个方法使用了相同的变量名。你最后一次声明驱动程序变量将是退出的那个。你应该为每个浏览器分别命名驱动程序,比如“chomreDriver”,然后退出所有的浏览器。