3

OS: Windows 10 Selenium Version: 3.11 Browser: Internet Explorer, Firefox, Opera, Chrome

Browser Version:

Expected Behavior - The program should launch all the browsers, open websites and perform operations intended.

Actual Behavior - The program behaves inconsistently during opening of browsers, sometimes throwing errors and failing to launch browsers. Error log can be found below (for one sample run):

Apr 09, 2018 12:09:21 AM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using new ChromeOptions() is preferred to DesiredCapabilities.chrome()
Test for the browser IE failed for website youtube
Exceptionorg.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'ADMIN-PC', ip: '192.168.1.5', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: InternetExplorerDriver
Test for the browser chrome failed for website google
Exceptionorg.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'ADMIN-PC', ip: '192.168.1.5', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: InternetExplorerDriver
Test for the browser Internet Explorer failed for website google
Test for the browser Opera failed for website google
Exception observedorg.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'ADMIN-PC', ip: '192.168.1.5', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: googleOperaDriver
Exceptionorg.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'ADMIN-PC', ip: '192.168.1.5', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: ChromeDriver
Test for the browser Firefox failed for website google
Exceptionorg.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:23410
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'ADMIN-PC', ip: '192.168.1.5', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: FirefoxDriver

Steps To Reproduce the error -

Sample Program (Please copy following files in eclipse and execute the program)

File 1

public class browserAutomation1 {
    public static void main(String[] args) {
        Thread googleOpera = new Thread(new GoogleOpera(), "GoogleOperaThread");
        googleOpera.start();
        Thread googleFirefox = new Thread(new GoogleFirefox(), "GoogleFirefoxThread");
        googleFirefox.start();
        Thread googleIE = new Thread(new GoogleIe(), "GoogleIEThread");
        googleIE.start();
        Thread googleChrome = new Thread(new GoogleChrome(), "GoogleChromeThread");
        googleChrome.start();
        //Thread youtubeIE= new Thread(new youtubeIE(),"YoutubeThread");
        //youtubeIE.start();
    }
}

File 2

package samplePrograms;

import java.io.File;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.opera.OperaDriver;
import org.openqa.selenium.opera.OperaOptions;

public class GoogleOpera extends browserAutomation1 implements Runnable {
    public void run() {
        System.setProperty("webdriver.opera.driver", "C:\\Marionette\\operadriver_win32\\operadriver.exe");
        OperaOptions options = new OperaOptions();
        options.setBinary(new File("C:\\Program Files\\Opera\\51.0.2830.55\\opera.exe"));
        try {
            WebDriver driver = new OperaDriver(options);
            driver.get("https://www.google.com");
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

File 3

package samplePrograms;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class GoogleChrome extends browserAutomation1 implements Runnable {
    public void run() {
        System.setProperty
                ("webdriver.chrome.driver", "C:\\Marionette\\chromedriver_win32_New\\chromedriver.exe");
        try {
            WebDriver driver = new ChromeDriver();
            driver.get("https://www.google.com");
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

File 4

package samplePrograms;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
import org.openqa.selenium.firefox.FirefoxOptions;

public class GoogleFirefox extends browserAutomation1 implements
        Runnable {

    public void run() {
        System.setProperty("webdriver.gecko.driver", "C:\\Marionette\\geckodriver.exe");
        try {
            FirefoxOptions options = new FirefoxOptions();
            options.setLogLevel(FirefoxDriverLogLevel.DEBUG);
            WebDriver driver = new FirefoxDriver(options);
            driver.get("https://www.google.com");
        } catch (Exception e) {
            System.out.println();
        }
    }
}

File 5

package samplePrograms;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

public class GoogleIe extends browserAutomation1 implements Runnable {
    public void run() {
        DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "IE");
        capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
        capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
        System.setProperty("webdriver.ie.driver", "C:\Marionette\IEDriverServer_Win32_3.9.0\IEDriverServer.exe");

        try {
            WebDriver driver = new InternetExplorerDriver();
            driver.get("https://www.google.com");
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

Hope this helps to understand the program output and the error.

  • Does your approach work with a single thread? – Alexey R. Apr 19 '18 at 15:12
  • And why does your Runnable classes extend browserAutomation1? – Alexey R. Apr 19 '18 at 15:19
  • The approach involves launching each browser with a new thread File 1 launches all four threads – Sudeept Apr 19 '18 at 15:29
  • This a sample program with minimal code for our audience to understand, Runnable classes extend browserAutomation because in real program all these classes use browserAutomation function, which i have omitted from mentioning here as our scope is only threading and associated problem – Sudeept Apr 19 '18 at 15:32
  • I mean to narrow the scope of root-causes you should try to start only one thread in your code. Thus we would know whether the issue is connected with multi-threading or not. – Alexey R. Apr 19 '18 at 15:40
2

The exception from your post indicates that the browser failed to launch within the allowed time. Either the browser crashed at some point or it is still loading.

The time to launch a browser depends on the hard disk IO performance which is usually slower in parallel depending on the type of disk or if your system is lacking memory.

Moreover, Selenium is exposed to a race condition on the selected port, especially on Windows. Basically it selects a free port and tells the driver to use it to communicate. But in the meantime a parallel instance could have selected the same port.

On top of that, any operation (launch included) needs to be executed in less than 60 seconds or you will get a timeout exception.

To overcome this issue, you can run your tests in parallel, but you should wait for a previous instance to be fully launched before launching the next one.

Note that there's also the case where the browser needs its main window to be the foreground one. I notice the behavior a while ago with Chrome. So an operation could be hanging for having its focus stolen by another instance.

Thread googleOpera = new Thread (new GoogleOpera(),"GoogleOperaThread");
Thread googleFirefox = new Thread (new GoogleFirefox(),"GoogleFirefoxThread");
Thread googleIE = new Thread (new GoogleIe(),"GoogleIEThread");
Thread googleChrome = new Thread (new GoogleChrome(),"GoogleChromeThread");

googleOpera.start();
Thread.sleep(6000);
googleIE.start();
Thread.sleep(6000);
googleFirefox.start();
Thread.sleep(6000);
googleChrome.start();
  • Thank you for a descriptive explanation, the solution suggested solves the problem, thanks a lot – Sudeept Apr 20 '18 at 14:22
  • Doesn’t the solution above simply make the threading sequential? – Rex Feb 18 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.