[英]Selenium webdriver : Multiple drivers
I have used 3 drivers firefox, chrome and IE for automated testing. 我已经使用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");
}
The problem is the second driver is starting before the first driver complete it's process. 问题是第二个驱动程序在第一个驱动程序完成处理之前就已启动。 How can i stop second driver till the first driver finish it work.
我如何才能停止第二个驱动程序,直到第一个驱动程序完成工作。
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)
}
}
You didn't mention your WebDriver version; 您没有提到您的WebDriver版本。 my comments are based on API 2.45.
我的评论基于API 2.45。
First, you should call driver.quit()
instead of close()
: 首先,您应该调用
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();
Second, you should secure the driver shutdown in a finally block: 其次,您应该在finally块中确保驱动程序关闭:
try {
testLogin(driver);
testSignupC(driver);
testSignUpCLogin(driver);
} catch(Exception ex) {
//log stack trace
//Alter(test failed in browser name)
} finally {
driver.quit();
}
Additionally, I would surround quit()
with a try/catch on WebDriverException
and set driver to null
in order to prevent its reuse since the driver initialization ( startClient()
, startSession()
...) is done in the constructor: 另外,我将在
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.