I like to run a selenium java test in a docker container. I was able to pull chrome image and created docker containers just fine. Then I configured remote webdriver by pointing to localhost of docker port. When I run the testNG test, I get the below error.
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
POM.xml
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.4.0</version>
</dependency>
Pulled docker images
docker pull selenium/standalone-chrome:latest
Created two docker containers
docker run -d -p 4441:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome:latest a79389eb6fec65b3f7af82348c717e9e4b83d9ac1c318c4e952714c55606041d
docker run -d -p 4440:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome:latest e507c986e2848b8009b748b98edcb7d285871640b5a5e15016ade6a8ff0df3bf
Listing the containers that are running
Created a testNG test
@Test public void test() throws MalformedURLException { String remote_url_chrome = "http://localhost:4440/wd/hub"; ChromeOptions chromeOptions = new ChromeOptions(); driver = new RemoteWebDriver(new URL(remote_url_chrome), chromeOptions); System.out.println("DockerGrid1"); driver.get("http://www.google.com"); wait(By.name("q")); System.out.println("google: " + driver.getTitle()); }
Run the testNG test and I get the following error:
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) Build info: version: '4.4.0', revision: 'e5c75ed026a' System info: host: 'e507c986e284', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.16.3-microsoft-standard-WSL2', java.version: '11.0.16' Driver info: driver.version: unknown Build info: version: '4.4.0', revision: 'e5c75ed026a' System info: host: 'e507c986e284', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.16.3-microsoft-standard-WSL2', java.version: '11.0.16' Driver info: driver.version: unknown Build info: version: '4.4.0', revision: 'e5c75ed026a' System info: host: 'DESKTOP-RF8H5GJ', ip: '192.168.1.248', os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '18.0.1.1' Driver info: org.openqa.selenium.remote.RemoteWebDriver Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}}}] Capabilities {} at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:144) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:102) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156) at org.openqa.selenium.remote.TracedCommandExecutor.execute(TracedCommandExecutor.java:51) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:547) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:157) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:139) at DockerGrid.BaseDockerGrid.startDockerGrid(BaseDockerGrid.java:46) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:577) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133) at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62) at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385) at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321) at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:176) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:122) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) at org.testng.TestRunner.privateRun(TestRunner.java:794) at org.testng.TestRunner.run(TestRunner.java:596) at org.testng.SuiteRunner.runTest(SuiteRunner.java:377) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332) at org.testng.SuiteRunner.run(SuiteRunner.java:276) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212) at org.testng.TestNG.runSuitesLocally(TestNG.java:1134) at org.testng.TestNG.runSuites(TestNG.java:1063) at org.testng.TestNG.run(TestNG.java:1031) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Visited this url in my browser http://localhost:4440/grid/console
How can I run the test in docker container?