繁体   English   中英

Selenium webdriver:多个驱动程序

[英]Selenium webdriver : Multiple drivers

我已经使用3种驱动程序firefox,chrome和IE进行了自动化测试。

static WebDriver driver ;
    public static void main(String args[]) {
        try {

            driver = new FirefoxDriver();
            runTest(driver, "FireFox");

            //Chrome
            System.setProperty("webdriver.chrome.driver","E:/selinium_drivers/chromedriver.exe");
            driver = new ChromeDriver();
            runTest(driver, "Chrome");

            //IE
            System.setProperty("webdriver.ie.driver","E:/selinium_drivers/IEDriverServer.exe");
            driver = new InternetExplorerDriver();
            runTest(driver, "IE");
            }

问题是第二个驱动程序在第一个驱动程序完成处理之前就已启动。 我如何才能停止第二个驱动程序,直到第一个驱动程序完成工作。

public static void runTest(WebDriver driver, String browserName) {
        try {
            testLogin(driver);
            testSignupC(driver);
            testSignUpCLogin(driver);
            driver.close();
        } catch(Exception ex) {
            //log stack trace
            //Alter(test failed in browser name)
        }
    }

您没有提到您的WebDriver版本。 我的评论基于API 2.45。

首先,您应该调用driver.quit()而不是close()

/**
 * Close the current window, quitting the browser if it's the last window currently open.
 */
void close();

/**
 * Quits this driver, closing every associated window.
 */
void quit();

其次,您应该在finally块中确保驱动程序关闭:

try {
    testLogin(driver);
    testSignupC(driver);
    testSignUpCLogin(driver);
} catch(Exception ex) {
    //log stack trace
    //Alter(test failed in browser name)
} finally {
    driver.quit();
}

另外,我将在WebDriverException上用try / catch包围quit() ,并将driver设置为null ,以防止其重用,因为驱动程序初始化( startClient()startSession() ...)是在构造函数中完成的:

} finally {
    try {
        driver.quit();
    catch (WebDriverException e) {
        // log if useful else NO OP
    }
    driver = null;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM