2

Java code in thread function,

System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("--user-data-dir="+config.chromeUserDir);
chromeOptions.addArguments("--profile-directory="+profile);
chromeOptions.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://www.google.com");

and create object and start in thread with following code

Driver d1 = new Driver(profile);
d1.start();

Driver d2 = new Driver(profile1);
d1.start();

Two different profiles have been created, code works well with single thread but with multiple threads it does not open google website in two separate windows, it says:

Starting ChromeDriver 2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac) on port 25692 Only local connections are allowed. Starting ChromeDriver 2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac) on port 25954 Only local connections are allowed. Oct 14, 2018 2:10:46 AM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS Oct 14, 2018 2:10:46 AM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS Created new window in existing browser session.

It opens google in only one window. The window opened by an another thread remains idle. Could anyone please help?

2 Answers 2

4
Driver d1 = new Driver(profile);
d1.start();

Driver d2 = new Driver(profile1);
d1.start();

Here you create Driver d2 but start d1.start() the second time then (you have started it two lines of code before)

2

You have not started d2. The code should look like this:

Driver d1 = new Driver(profile);
d1.start();

Driver d2 = new Driver(profile1);
d2.start();

Your Answer

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

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