Reputation: 135
I have used 3 drivers firefox, chrome and IE for automated testing.
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)
}
}
Upvotes: 1
Views: 4084
Reputation: 3995
You didn't mention your WebDriver version; my comments are based on API 2.45.
First, you should call driver.quit()
instead of 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:
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:
} finally {
try {
driver.quit();
catch (WebDriverException e) {
// log if useful else NO OP
}
driver = null;
}
Upvotes: 4