chromedriver:无法执行二进制文件,并且无法通过 Java 使用 ChromeDriver Selenium 将会话 null 上的 newSession 严重转发到远程

chromedriver: cannot execute binary file and SEVERE Forwarding newSession on session null to remote with ChromeDriver Selenium through Java

我有一项服务正在使用 selenium 以 chrome headless 模式启动 chrome webdriver。该应用程序通过 tomcat8 启动。我可以 运行 在我的 mac.

本地毫无问题地使用该服务

但是当我通过AWS Elastic Beanstalk部署到ec2节点后,webdriver无法正常启动:

28-Feb-2019 03:32:48.944 SEVERE [http-nio-8080-exec-7] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [registerCustomer] in context with path [] threw exception
 org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'ip-172-31-16-234', ip: '172.31.16.234', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.97-74.72.amzn1.x86_64', java.version: '1.8.0_191'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:192)
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:178)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157)
    at com.christina.insbot.factory.BrowserDriverFactory.createWebDriver(BrowserDriverFactory.java:64)
    at com.christina.insbot.service.InsBot.<init>(InsBot.java:86)
    at com.christina.insbot.service.servlet.RegisterCustomerService.doPost(RegisterCustomerService.java:93)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:685)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:13611/status] to be available after 20010 ms
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:187)
    ... 36 more
Caused by: java.util.concurrent.TimeoutException
    at java.util.concurrent.FutureTask.get(FutureTask.java:205)
    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:147)
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
    ... 37 more

CATALINA 错误:

/var/lib/tomcat8/webapps/ROOT/webdriver/chromedriver: /var/lib/tomcat8/webapps/ROOT/webdriver/chromedriver: cannot execute binary file
28-Feb-2019 03:32:48.926 SEVERE [Forwarding newSession on session null to remote] org.openqa.selenium.os.OsProcess.checkForError org.apache.commons.exec.ExecuteException: Process exited with an error: 126 (Exit value: 126)

我启动webdriver的方式是这样的:

        ChromeOptions options = new ChromeOptions();
        // "--headless",
        options.addArguments("--disable-gpu", "--window-size=1920,1200",
                "--ignore-certificate-errors", "--silent");

        if (useHeadlessMode) {
            options.addArguments("--headless");
        }


        System.setProperty("webdriver.chrome.driver", EnvironmentInitialization.obtainChromeDriverPath());

        webDriver = new ChromeDriver(options);

这个错误信息...

28-Feb-2019 03:32:48.944 SEVERE [http-nio-8080-exec-7] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [registerCustomer] in context with path [] threw exception
 org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'ip-172-31-16-234', ip: '172.31.16.234', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.97-74.72.amzn1.x86_64', java.version: '1.8.0_191'
Driver info: driver.version: ChromeDriver

...表示您的程序无法在 headless[=105= 中 initiate/spawn 新的 ChromeDriver 服务]模式。

此外,此错误消息...

/var/lib/tomcat8/webapps/ROOT/webdriver/chromedriver: /var/lib/tomcat8/webapps/ROOT/webdriver/chromedriver: cannot execute binary file
28-Feb-2019 03:32:48.926 SEVERE [Forwarding newSession on session null to remote] org.openqa.selenium.os.OsProcess.checkForError org.apache.commons.exec.ExecuteException: Process exited with an error: 126 (Exit value: 126)

...意味着您的程序无法执行 chromedriver 二进制文件,因此 null 会话被转发到 RemoteWebServer.


有关 ChromeDriverChromeBrowser 版本的更多信息帮助我们以更好的方式调试您的问题。但是,您需要注意以下几个事实:


解决方案

  • JDK 升级到最近的水平 JDK 8u201
  • Selenium 升级到当前水平 Version 3.141.59
  • Chrome驱动程序升级到当前ChromeDriver v2.46级别。
  • 保持 Chrome 版本在 Chrome v71-73[=104= 之间] 水平。 (as per ChromeDriver v2.46 release notes)
  • 清理你的项目工作区通过你的IDE重建你的项目只需要依赖。
  • (LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint 在你的测试套件[=105执行之前和之后=].
  • 如果您的基础 Web 客户端 版本太旧,则通过 Revo Uninstaller 卸载它并安装最新的 GA 和发布版本的 Web 客户端.
  • 确保Chrome驱动程序出现在指定位置。
  • 确保Chrome驱动程序具有非root用户的可执行权限。
  • 系统重启
  • 非 root 用户身份执行您的 @Test
  • 始终在 tearDown(){} 方法中调用 driver.quit() 以优雅地关闭和销毁 WebDriverWeb Client 实例.

琐事

您可以在以下位置找到一些相关讨论: