Upgrade to Silenium 4. JUnit.

238 views
Skip to first unread message

Alexander Sundukov

unread,
Oct 18, 2021, 2:12:44 AM10/18/21
to Selenium Users
Hello.
When switching to selenium 4, I encountered the following problem, in the new version, the following code gives the error "org.openqa.selenium.SessionNotCreatedException exception: Failed to start a new session. Possible reasons are an incorrect address of the remote server or a failure when launching the browser.":

WebDriver Driver = new RemoteWebDriver(url, chromeOptions);
driver. to close;
driver = new ChromeDriver (service, ChromeOptions);

ChromeOptions are installed as follows:

final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("--disable-dev-shm-usage");
chromeOptions.addArguments("--lang=en");
chromeOptions.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
chromeOptions.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
chromeOptions.addArguments("--disable-extensions");
chromeOptions.addArguments("--ignore-certificate-errors");
chromeOptions.addArguments("disable-infobars");


In silenium 3, this code worked perfectly! Perhaps this is a limitation of the new version, or I just need other settings, or a bug.
I will be glad of any help.

Krishnan Mahadevan

unread,
Oct 18, 2021, 3:49:32 AM10/18/21
to seleniu...@googlegroups.com

A quick fix would be to check if there’s a new chromedriver binary that is available for download and update the chromedriver binary at your local machine.

Between selenium 3 and selenium 4 a lot of things have changed and improvised, but am pretty sure that the basics (which is what your sample code does) remains the same.

 

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribblings @ https://rationaleemotions.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/f5f1c60a-0d88-4115-b196-c83085cbdf7bn%40googlegroups.com.

Alexander Sundukov

unread,
Oct 18, 2021, 4:12:20 AM10/18/21
to Selenium Users
Hello Krishnan Mahadevan, thank you for your reply.
I probably didn't describe it in detail, but the bottom line is that after the first instance of the web driver is created, everything works fine, but if you close it and try to create it again, an error occurs. The web driver version is the latest!
Simplified it looks like this:

WebDriver Driver = new RemoteWebDriver(url, chromeOptions);

//everything works fine here

driver. close();

driver = new RemoteWebDriver(url, chromeOptions); //Failed to start a new session

⇜Krishnan Mahadevan⇝

unread,
Oct 19, 2021, 2:36:27 AM10/19/21
to Selenium Users
So is this a problem when you are using RemoteWebDriver in conjunction with a Selenium Grid?
If its a selenium grid, can you please let us know if you are using Selenium Grid3 or Grid4 ?

Also please do share the commands you are using to bring up your Selenium Grid (Hub and nodes)

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

Alexander Sundukov

unread,
Oct 19, 2021, 10:37:07 AM10/19/21
to Selenium Users
No we don't use Grid. To create a web driver, we use:

docker-compose up -d

docker-compose.yml:

version: '2.2'
services:
...
selenium:
image: selenium/standalone-chrome:latest
container_name: selenium_container
ports:
- selenium_port:4444
volumes:
- /dev/shm:/dev/shm

⇜Krishnan Mahadevan⇝

unread,
Oct 19, 2021, 2:03:52 PM10/19/21
to Selenium Users
Alexander,
I spent some time on this. I was not able to reproduce the problem per se as detailed by you.

Here's the docker file that I used:

version: '2.2'
services:
selenium:
image: selenium/standalone-chrome:4.0.0-20211013
container_name: selenium_container
ports:
- 4444:4444
volumes:
- /dev/shm:/dev/shm
environment:
- JAVA_OPTS=-Dwebdriver.chrome.whitelistedIps=

It looks like driver.close() is not killing the session and because of that my test was stalling indefinitely. I had to replace driver.close() with a call to driver.quit() after which the test ran fine.

import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;

public class SampleTestClass {

private RemoteWebDriver driver;
private static URL url;

static {
try {
url = new URL("http://127.0.0.1:4444/wd/hub");
} catch (MalformedURLException e) {
e.printStackTrace();
}
}

@BeforeMethod
public void setup() {
driver = new RemoteWebDriver(url, new ChromeOptions());
}

@Test
public void testMethod() {
driver.get("https://www.google.com");
// driver.close(); This will cause the test to stall.
driver.quit();
driver = new RemoteWebDriver(url, new ChromeOptions());
driver.get("https://www.facebook.com");
}

@AfterMethod
public void tearDown() {
driver.quit();
}
}


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

Alexander Sundukov

unread,
Oct 20, 2021, 5:56:46 PM10/20/21
to Selenium Users
Hello, Krishnan! Thank you so much for your help! I managed to understand that the web driver freezes if I execute the code

new ChromeDriver(service, chromeOptions);
...
// some code, but not "driver.quit();"
...
new ChromeDriver(service, chromeOptions);


The same thing happens when the docker memory is full. In these cases, after waiting for a long time, we get an error: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
That is, it is not noticeable for simple tests, but we run more than 300 tests in 8 threads, and this becomes a problem. Everything works fine in selenium 3, I think we'll just postpone the update until better times.
Reply all
Reply to author
Forward
0 new messages