0
votes

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.

1
driver1 and driver2. driver = firefox followed by driver = chrome leaves firefox without a handle. - MikeJRamsey56
@Mike I didn't get you. Can you explain with a solution - Ashok kumar Ganesan
You want two concurrent browser sessions but in the provided code you only define one variable driver. To have two browser sessions open concurrently you would need to initialize driver1 = new FirefoxDriver(); driver2 = new InternetExplorerDriver(); - MikeJRamsey56
Mike, but in some tutorials I do see with one driver using testNG they are able to run concurrently. As I mentioned in the code. - Ashok kumar Ganesan
Two driver instances is two driver variables. :-) - MikeJRamsey56

1 Answers

1
votes

I think you need to make driver a member variable, not a NOT static variable.