每当新窗口打开时,close()都不起作用

时间:2017-01-28 18:57:29

标签: java selenium selenium-webdriver

我正在尝试运行下面提到的代码,它不起作用,每次打开一个新窗口而不是关闭当前窗口并打开一个窗口。

public class Next2beforendafter {

    public static WebDriver driver;

    @BeforeMethod
    public void launchBrowser() {
        System.setProperty("webdriver.gecko.driver", "C:/Users/xyz/Videos/selenium/geckodriver-v0.11.1-win64/geckodriver.exe");
        driver = new FirefoxDriver();
    }

    @Test(priority = 1)
    public void verifygoogleTitle() {
        driver.get("http://www.google.com");
        Assert.assertEquals("Google", driver.getTitle());
    }

    @Test(priority = 2)
    public void verifyyahooTitle() {
        driver.get("https://in.yahoo.com");
        Assert.assertEquals("Yahoo", driver.getTitle());
    }

    @Test(priority = 3)
    public void verifybankofindiaTitle() {
        driver.get("http://www.bankofindia.co.in/english/home.aspx");
        Assert.assertEquals("Bank Of India - Home", driver.getTitle());
    }

    @AfterMethod
    public void closeBrowser() {
        driver.close();
    }
}

Selenium Ver.3.0.1

1 个答案:

答案 0 :(得分:1)

如果要关闭webdriver,则应该使用driver.quit()driver.close()仅关闭当前窗口(选项卡)但保持驱动程序会话打开