0

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.

5
  • driver1 and driver2. driver = firefox followed by driver = chrome leaves firefox without a handle. Commented Apr 23, 2016 at 3:00
  • @Mike I didn't get you. Can you explain with a solution Commented Apr 23, 2016 at 15:38
  • 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(); Commented Apr 24, 2016 at 0:45
  • 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. Commented Apr 25, 2016 at 3:50
  • Two driver instances is two driver variables. :-) Commented Apr 25, 2016 at 13:43

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I changed the static variable to a member variable now it works fine. But IE is not entering the value in google search box. I tried with id, name, xpath but everything fails. But the same thing works in Chrome and Firefox.
It fails in IE11 and it works in IE10 32bit. That's fine. Can you explain me the concept behind the parallel test. With the help of one driver 3 instances are created and how come the session id is maintained and managed throughout the flow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.