webdrivermanager icon indicating copy to clipboard operation
webdrivermanager copied to clipboard

java.lang.RuntimeException: java.io.IOException: com.sun.jna.LastErrorException

Open artur-oliveira opened this issue 2 years ago • 3 comments

Description of the problem: Cannot create WebDriver in Docker using coretto JDK

Browser and version: Latest (Current 103.0.5060.53)

Operating system: Amazon Linux 2 (Linux 5.13.0-51-generic)

WebDriverManager version: 5.2.0

WebDriverManager call: WebDriverManager.chromedriver().avoidBrowserDetection().browserInDocker().capabilities(new ChromeOptions().addArguments("--headless")).enableVnc().enableRecording().create();

WebDriverManager traces: 2022-06-27 15:02:37.493 ERROR 1 --- [lTaskExecutor-5] i.g.bonigarcia.wdm.WebDriverManager : There was an error creating WebDriver object for Chrome 2022-06-27T15:02:37.493479007Z 2022-06-27T15:02:37.493488690Z java.lang.RuntimeException: java.io.IOException: com.sun.jna.LastErrorException: [2] No such file or directory 2022-06-27T15:02:37.493496609Z at com.github.dockerjava.httpclient5.ApacheDockerHttpClientImpl.execute(ApacheDockerHttpClientImpl.java:195) ~[docker-java-transport-httpclient5-3.2.13.jar!/:na] 2022-06-27T15:02:37.493503385Z at com.github.dockerjava.httpclient5.ApacheDockerHttpClient.execute(ApacheDockerHttpClient.java:9) ~[docker-java-transport-httpclient5-3.2.13.jar!/:na] 2022-06-27T15:02:37.493510349Z at com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:228) ~[docker-java-core-3.2.13.jar!/:na] 2022-06-27T15:02:37.493517572Z at com.github.dockerjava.core.DefaultInvocationBuilder.post(DefaultInvocationBuilder.java:124) ~[docker-java-core-3.2.13.jar!/:na] 2022-06-27T15:02:37.493525424Z at com.github.dockerjava.core.exec.CreateContainerCmdExec.execute(CreateContainerCmdExec.java:37) ~[docker-java-core-3.2.13.jar!/:na] 2022-06-27T15:02:37.493532948Z at com.github.dockerjava.core.exec.CreateContainerCmdExec.execute(CreateContainerCmdExec.java:13) ~[docker-java-core-3.2.13.jar!/:na] 2022-06-27T15:02:37.493540250Z at com.github.dockerjava.core.exec.AbstrSyncDockerCmdExec.exec(AbstrSyncDockerCmdExec.java:21) ~[docker-java-core-3.2.13.jar!/:na] 2022-06-27T15:02:37.493547308Z at com.github.dockerjava.core.command.AbstrDockerCmd.exec(AbstrDockerCmd.java:35) ~[docker-java-core-3.2.13.jar!/:na] 2022-06-27T15:02:37.493560409Z at com.github.dockerjava.core.command.CreateContainerCmdImpl.exec(CreateContainerCmdImpl.java:608) ~[docker-java-core-3.2.13.jar!/:na] 2022-06-27T15:02:37.493564565Z at io.github.bonigarcia.wdm.docker.DockerService.startContainer(DockerService.java:243) ~[webdrivermanager-5.2.0.jar!/:na] 2022-06-27T15:02:37.493568914Z at io.github.bonigarcia.wdm.docker.DockerService.startBrowserContainer(DockerService.java:644) ~[webdrivermanager-5.2.0.jar!/:na] 2022-06-27T15:02:37.493573103Z at io.github.bonigarcia.wdm.WebDriverManager.createDockerWebDriver(WebDriverManager.java:1820) [webdrivermanager-5.2.0.jar!/:na] 2022-06-27T15:02:37.493578758Z at io.github.bonigarcia.wdm.WebDriverManager.instantiateDriver(WebDriverManager.java:1713) [webdrivermanager-5.2.0.jar!/:na] 2022-06-27T15:02:37.493583248Z at io.github.bonigarcia.wdm.WebDriverManager.create(WebDriverManager.java:412) [webdrivermanager-5.2.0.jar!/:na] 2022-06-27T15:02:37.493587204Z at com.tartigrado.anpapi.automation.AnpPage.(AnpPage.java:30) [classes!/:0.0.1-SNAPSHOT] 2022-06-27T15:02:37.493591358Z at com.tartigrado.anpapi.automation.AnpAction.(AnpAction.java:13) [classes!/:0.0.1-SNAPSHOT] 2022-06-27T15:02:37.493595621Z at com.tartigrado.anpapi.services.impl.CertificadoServiceImpl.emitir(CertificadoServiceImpl.java:134) [classes!/:0.0.1-SNAPSHOT] 2022-06-27T15:02:37.493599755Z at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_332] 2022-06-27T15:02:37.493603921Z at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_332] 2022-06-27T15:02:37.493614820Z at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_332] 2022-06-27T15:02:37.493619278Z at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_332] 2022-06-27T15:02:37.493623303Z at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:169) [spring-messaging-5.3.12.jar!/:5.3.12] 2022-06-27T15:02:37.493627426Z at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:119) [spring-messaging-5.3.12.jar!/:5.3.12] 2022-06-27T15:02:37.493631521Z at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:569) [spring-messaging-5.3.12.jar!/:5.3.12] 2022-06-27T15:02:37.493635792Z at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessageInternal(AbstractMethodMessageHandler.java:524) [spring-messaging-5.3.12.jar!/:5.3.12] 2022-06-27T15:02:37.493641535Z at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessage(AbstractMethodMessageHandler.java:458) [spring-messaging-5.3.12.jar!/:5.3.12] 2022-06-27T15:02:37.493648812Z at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.executeMessage(SimpleMessageListenerContainer.java:228) [spring-cloud-aws-messaging-2.2.6.RELEASE.jar!/:2.2.6.RELEASE] 2022-06-27T15:02:37.493656845Z at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$MessageExecutor.run(SimpleMessageListenerContainer.java:418) [spring-cloud-aws-messaging-2.2.6.RELEASE.jar!/:2.2.6.RELEASE] 2022-06-27T15:02:37.493661623Z at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$SignalExecutingRunnable.run(SimpleMessageListenerContainer.java:310) [spring-cloud-aws-messaging-2.2.6.RELEASE.jar!/:2.2.6.RELEASE] 2022-06-27T15:02:37.493666101Z at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_332] 2022-06-27T15:02:37.493670002Z at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_332] 2022-06-27T15:02:37.493673897Z at java.lang.Thread.run(Thread.java:750) [na:1.8.0_332] 2022-06-27T15:02:37.493677826Z Caused by: java.io.IOException: com.sun.jna.LastErrorException: [2] No such file or directory 2022-06-27T15:02:37.493681772Z at com.github.dockerjava.transport.DomainSocket.(DomainSocket.java:63) ~[docker-java-transport-3.2.13.jar!/:na] 2022-06-27T15:02:37.493686231Z at com.github.dockerjava.transport.LinuxDomainSocket.(LinuxDomainSocket.java:41) ~[docker-java-transport-3.2.13.jar!/:na] 2022-06-27T15:02:37.493690585Z at com.github.dockerjava.transport.DomainSocket.get(DomainSocket.java:140) ~[docker-java-transport-3.2.13.jar!/:na] 2022-06-27T15:02:37.493694923Z at com.github.dockerjava.transport.UnixSocket.get(UnixSocket.java:29) ~[docker-java-transport-3.2.13.jar!/:na] 2022-06-27T15:02:37.493699066Z at com.github.dockerjava.httpclient5.ApacheDockerHttpClientImpl$2.createSocket(ApacheDockerHttpClientImpl.java:153) ~[docker-java-transport-httpclient5-3.2.13.jar!/:na] 2022-06-27T15:02:37.493714293Z at org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:125) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493719602Z at org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:409) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493724053Z at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:168) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493728143Z at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:178) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493732618Z at org.apache.hc.client5.http.impl.classic.ConnectExec.execute(ConnectExec.java:135) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493740057Z at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493745117Z at org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493751667Z at org.apache.hc.client5.http.impl.classic.ProtocolExec.execute(ProtocolExec.java:172) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493758282Z at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493762973Z at org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493769816Z at org.apache.hc.client5.http.impl.classic.HttpRequestRetryExec.execute(HttpRequestRetryExec.java:93) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493778006Z at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493784849Z at org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493792366Z at org.apache.hc.client5.http.impl.classic.ContentCompressionExec.execute(ContentCompressionExec.java:128) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493796777Z at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493800959Z at org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493805020Z at org.apache.hc.client5.http.impl.classic.RedirectExec.execute(RedirectExec.java:116) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493809046Z at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493813211Z at org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(InternalHttpClient.java:178) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493821812Z at org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:67) ~[httpclient5-5.0.4.jar!/:5.0.4] 2022-06-27T15:02:37.493828006Z at com.github.dockerjava.httpclient5.ApacheDockerHttpClientImpl.execute(ApacheDockerHttpClientImpl.java:191) ~[docker-java-transport-httpclient5-3.2.13.jar!/:na] 2022-06-27T15:02:37.493832520Z ... 31 common frames omitted 2022-06-27T15:02:37.493836658Z Caused by: com.sun.jna.LastErrorException: [2] No such file or directory 2022-06-27T15:02:37.493847959Z at com.github.dockerjava.transport.LinuxDomainSocket.connect(Native Method) ~[docker-java-transport-3.2.13.jar!/:na] 2022-06-27T15:02:37.493855368Z at com.github.dockerjava.transport.LinuxDomainSocket.connect(LinuxDomainSocket.java:49) ~[docker-java-transport-3.2.13.jar!/:na] 2022-06-27T15:02:37.493860637Z at com.github.dockerjava.transport.DomainSocket.open(DomainSocket.java:69) ~[docker-java-transport-3.2.13.jar!/:na] 2022-06-27T15:02:37.493864851Z at com.github.dockerjava.transport.DomainSocket.(DomainSocket.java:59) ~[docker-java-transport-3.2.13.jar!/:na] 2022-06-27T15:02:37.493868967Z ... 56 common frames omitted 2022-06-27T15:02:37.493873202Z

Dockerfile.txt

artur-oliveira avatar Jun 27 '22 15:06 artur-oliveira

I've just run a test using your command, and it works nicely. This is the test:

class DockerChromeTest {

    WebDriver driver;

    WebDriverManager wdm = WebDriverManager.chromedriver()
            .avoidBrowserDetection().browserInDocker()
            .capabilities(new ChromeOptions().addArguments("--headless"))
            .enableVnc().enableRecording();

    @BeforeEach
    void setupTest() {
        driver = wdm.create();
    }

    @AfterEach
    void teardown() {
        wdm.quit();
    }

    @Test
    void test() {
        driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
        assertThat(driver.getTitle()).contains("Selenium WebDriver");
    }

}

And this is the output:

2022-07-27 16:27:44 [main] DEBUG i.g.b.wdm.docker.DockerHubService.listTags(60) -- Getting browser image list from Docker Hub
2022-07-27 16:27:46 [main] DEBUG i.g.b.wdm.docker.DockerService.getImageVersionFromDockerHub(440) -- The latest version of Chrome in Docker Hub is 103.0
2022-07-27 16:27:46 [main] INFO  i.g.b.wdm.docker.DockerService.pullImageIfNecessary(299) -- Pulling Docker image selenoid/vnc:chrome_103.0 (this might take some time, but only the first time)
2022-07-27 16:28:09 [main] DEBUG i.g.b.wdm.cache.ResolutionCache.putValueInResolutionCacheIfEmpty(119) -- Storing resolution chrome-container-latest=103.0 in cache (valid until 17:28:09 27/07/2022 CEST)
2022-07-27 16:28:09 [main] INFO  i.g.b.wdm.docker.DockerService.startContainer(173) -- Starting Docker container selenoid/vnc:chrome_103.0
2022-07-27 16:28:09 [main] DEBUG i.g.b.wdm.docker.DockerService.startBrowserContainer(667) -- VNC server URL: vnc://localhost:49153/
2022-07-27 16:28:09 [main] DEBUG i.g.b.wdm.webdriver.WebDriverCreator.createRemoteWebDriver(77) -- Creating WebDriver object for chrome at http://localhost:49154/ with Capabilities {browserName: chrome, goog:chromeOptions: {args: [--disable-gpu, --headless], extensions: []}}
Jul 27, 2022 4:28:10 PM org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer createTracer
INFO: Using OpenTelemetry for tracing
Jul 27, 2022 4:28:11 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected upstream dialect: W3C
2022-07-27 16:28:11 [main] DEBUG i.g.b.wdm.webdriver.WebDriverCreator.getSessionId(115) -- The sessionId is 783878ad97373221e9ec8bde8a78e7ee
2022-07-27 16:28:11 [main] DEBUG i.g.b.wdm.cache.ResolutionCache.checkValidity(156) -- Removing resolution novnc-container=1.1.0 from cache (expired on Fri Jun 03 06:31:11 CEST 2022)
2022-07-27 16:28:11 [main] INFO  i.g.b.wdm.docker.DockerService.pullImageIfNecessary(299) -- Pulling Docker image bonigarcia/novnc:1.1.0 (this might take some time, but only the first time)
2022-07-27 16:28:13 [main] DEBUG i.g.b.wdm.cache.ResolutionCache.putValueInResolutionCacheIfEmpty(119) -- Storing resolution novnc-container=1.1.0 in cache (valid until 17:28:13 27/07/2022 CEST)
2022-07-27 16:28:13 [main] INFO  i.g.b.wdm.docker.DockerService.startContainer(173) -- Starting Docker container bonigarcia/novnc:1.1.0
2022-07-27 16:28:13 [main] INFO  i.g.bonigarcia.wdm.WebDriverManager.createDockerWebDriver(1896) -- Docker session noVNC URL: http://localhost:49155/
2022-07-27 16:28:13 [main] INFO  i.g.b.wdm.docker.DockerService.pullImageIfNecessary(299) -- Pulling Docker image selenoid/video-recorder:7.1 (this might take some time, but only the first time)
2022-07-27 16:28:20 [main] DEBUG i.g.b.wdm.cache.ResolutionCache.putValueInResolutionCacheIfEmpty(119) -- Storing resolution recorder-container=7.1 in cache (valid until 17:28:20 27/07/2022 CEST)
2022-07-27 16:28:20 [main] INFO  i.g.b.wdm.docker.DockerService.startContainer(173) -- Starting Docker container selenoid/video-recorder:7.1
2022-07-27 16:28:20 [main] INFO  i.g.bonigarcia.wdm.WebDriverManager.createDockerWebDriver(1910) -- Starting recording ./chrome_2022.07.27_16.28.20.313_783878ad97373221e9ec8bde8a78e7ee.mp4
2022-07-27 16:28:21 [main] DEBUG i.g.bonigarcia.wdm.WebDriverManager.quit(956) -- Quitting RemoteWebDriver: chrome on LINUX (783878ad97373221e9ec8bde8a78e7ee)
2022-07-27 16:28:21 [main] INFO  i.g.b.wdm.docker.DockerService.stopAndRemoveContainer(323) -- Stopping Docker container selenoid/video-recorder:7.1
2022-07-27 16:28:23 [main] INFO  i.g.b.wdm.docker.DockerService.stopAndRemoveContainer(323) -- Stopping Docker container selenoid/vnc:chrome_103.0
2022-07-27 16:28:23 [main] INFO  i.g.b.wdm.docker.DockerService.stopAndRemoveContainer(323) -- Stopping Docker container bonigarcia/novnc:1.1.0

I run it in Linux and Windows, and both operating systems work.

I guess your problem is you do not have access to Docker. If you are running this into a container, then I think you need Docker in Docker.

bonigarcia avatar Jul 27 '22 14:07 bonigarcia

@bonigarcia I have tried your code, and I see an issue with method wdm.create(). It returns null if it failed to create webdriver, which causes NPE in the following tests. I believe it should throw an exception instead.

   @BeforeEach
    void setupTest() {
        driver = wdm.create();
         // logs WebDriverManager... ("Timeout of 30 seconds creating WebDriver object")
         // BUT returns null
    }

    @Test
    void test() {
        driver.get("https://bonigarcia.dev/selenium-webdriver-java/"); // causes NullPointerException because `driver` is null
    }

asolntsev avatar Jul 27 '22 16:07 asolntsev

I have just released WDM 5.2.2. This version includes the latest PRs about NPE handling. In any case, the Docker support should work (of course, Docker should be installed in the machine running the test).

bonigarcia avatar Jul 29 '22 00:07 bonigarcia

@bonigarcia I am able to create wdm instance and assign it to driver when i run it on my local , but same thing fails when i run the tests inside docker container

Here is the dockerfile i am using

FROM maven:3-eclipse-temurin-11 WORKDIR /home/app

RUN apt-get update &&
apt-get install -y wget &&
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb &&
apt-get install ./google-chrome-stable_current_amd64.deb -y &&
rm ./google-chrome-stable_current_amd64.deb

COPY src src COPY *.xml ./

Here is the wdm instance created

            WebDriverManager wdm = WebDriverManager.chromedriver()
                    .avoidBrowserDetection().browserInDocker()
                    .capabilities(new ChromeOptions().addArguments("--headless"))
                    .enableVnc().enableRecording();
            //driver.manage().window().maximize();
            driver=wdm.create();
            logger.info("driver initialised is" +driver);

Error trace

/root/.cache/selenium/chromedriver/linux64/105.0.5195.52/chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

Running TestSuite 2022-09-28 05:44:03 INFO [main] BasePage:55 - Intializing Driver 2022-09-28 05:44:03 INFO [main] BasePage:81 - assigning driver based on option 2022-09-28 05:44:03 INFO [main] BasePage:86 - options for capabilitiesCapabilities {browserName: chrome, goog:chromeOptions: {args: [--disable-dev-shm-usage, headless, --headless], extensions: []}} 2022-09-28 05:44:05 INFO [main] BasePage:90 - driver initialised isnull 2022-09-28 05:44:05 INFO [main] BasePage:91 - driver optionsCapabilities {browserName: chrome, goog:chromeOptions: {args: [--disable-dev-shm-usage, headless, --headless], extensions: []}} 2022-09-28 05:44:05 INFO [main] BasePage:60 - java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.WebDriver.toString()" because the return value of "java.lang.ThreadLocal.get()" is null

abhiram165 avatar Sep 28 '22 06:09 abhiram165