Reputation: 1128
I run a parallel multiple browser test in selenium webdriver. When it is launched for the first time it runs in chrome as well as in firefox.
From the second time, two browsers are launched with the mentioned URL. Then the further actions are occurring only in firefox. The chrome browser is simply displaying the url of the page.
Java code:
public class Browser {
static WebDriver driver;
@BeforeTest
@Parameters("browser")
public void setup(String browserName) throws Exception{
if (browserName.equalsIgnoreCase("Firefox")) {
driver = new FirefoxDriver();
}
else if (browserName.equalsIgnoreCase("Chrome")) {
System.setProperty("webdriver.chrome.driver",
"C:/Users/MSTEMP/Downloads/Softwares/chromedriver_win32/chromedriver.exe");
driver = new ChromeDriver();
}
else if (browserName.equalsIgnoreCase("ie")) {
System.setProperty("webdriver.ie.driver",
"C:/Users/MSTEMP/Downloads/Softwares/IEDriverServer/IEDriverServer.exe");
driver = new InternetExplorerDriver();
}
else {
throw new Exception("Browser is not correct");
}
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void testParameterWithXML() throws InterruptedException{
driver.get("https://www.google.co.in/");
System.out.println(""+driver.toString());
driver.findElement(By.name("q")).sendKeys("login");
}
}
Testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Automationsuite" parallel="tests">
<test name="ChromeTest">
<parameter name ="browser" value="Chrome"/>
<classes>
<class name="browser.Browser" />
</classes>
</test>
<test name="FirefoxTest">
<parameter name ="browser" value="Firefox"/>
<classes>
<class name="browser.Browser" />
</classes>
</test>
</suite>
Console: C:\Users\MSTEMP\workspace\CrossBrowser\src\browser.xml
Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 16536
Only local connections are allowed.
FirefoxDriver: firefox on WINDOWS (e787139a-cce5-4406-9eff-c856151a9b20)
FirefoxDriver: firefox on WINDOWS (e787139a-cce5-4406-9eff-c856151a9b20)
===============================================
Automationsuite Total tests run: 2, Failures: 0, Skips: 0
===============================================
System Specification:
OS: Windows 7 64 bit
Java: Java 8
Selenium: 2.53.0
Guide me to reach out.
Upvotes: 0
Views: 15512
Reputation: 1982
I think you need to make driver a member variable, not a NOT static variable.
Upvotes: 1