如何解决:消息:org.openqa.selenium.WebDriverException:无法访问chrome

时间:2019-05-16 10:17:05

标签: selenium google-chrome jenkins

我正在Jenkins ECS从站上使用ChromeDriver设置基于硒的回归测试。

ChromeDriver使用Maven插件"driver-binary-downloader-maven-plugin"

安装在ECS从站上

登录docker容器时,我看到安装了ChromeDriver /usr/bin/linux/googlechrome/64bit/chromedriver

Docker容器以--privileged

开始

pom.xml

<plugin>
    <groupId>com.lazerycode.selenium</groupId>
    <artifactId>driver-binary-downloader-maven-plugin</artifactId>
    <version>1.0.17</version>
    <configuration>
        <rootStandaloneServerDirectory>/usr/bin</rootStandaloneServerDirectory>
        <downloadedZipFileDirectory>drivers/zips</downloadedZipFileDirectory>
    </configuration>
    <executions>
        <execution>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>selenium</goal>
            </goals>
        </execution>
    </executions>
</plugin>

BrowserDriverHolder.java

private WebDriver createDriver(final String driverName, final String headless) {
    ChromeOptions options = new ChromeOptions();
    if (headless.toLowerCase().equals("true")) {
      options.addArguments("headless");
    }

    options.addArguments("debug");
    options.addArguments("no-sandbox");

    options.setBinary("/usr/bin/linux/googlechrome/64bit/chromedriver");
    System.setProperty("webdriver.chrome.driver", "/usr/bin/linux/googlechrome/64bit/chromedriver");
    options.addArguments("window-size=1920,1080");
    ChromeDriver driver = new ChromeDriver(options);

    driver.manage().window().maximize();
    driver.manage().timeouts().pageLoadTimeout(360, TimeUnit.SECONDS);
    driver.manage().timeouts().setScriptTimeout(360, TimeUnit.SECONDS);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    return driver;
}

ECS容器成功启动并开始回归测试,并显示以下错误消息:

Starting ChromeDriver 2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4) on port 19809
Only local connections are allowed.
Starting ChromeDriver 2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4) on port 9515
Only local connections are allowed.
Message: org.openqa.selenium.WebDriverException: chrome not reachable
  (Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 4.14.77-69.57.amzn1.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.17 seconds
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'ip-172-27-93-92.eu-central-1.compute.internal', ip: '172.27.93.92', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.77-69.57.amzn1.x86_64', java.version: '9.0.4'
Driver info: driver.version: ChromeDriver
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
    at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:476)

ChromeDriver正在运行并且正在侦听给定的端口。

我正在努力寻找解决方案,感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您计算机上的chromedriver版本和Google Chrome二进制文件之间很可能不匹配。

  1. 您的Maven插件似乎正在下载Chromedriver version 2.33
  2. 查看Chromedriver 2.33 release notes

      

    支持Chrome v60-62

因此,您要么需要增加chromedriver版本,要么将Chrome的版本降级到60到62之间。

我还相信选项必须以2个破折号开头,例如:

options.addArguments("--headless")

如果您不能负担得起降级浏览器或升级驱动程序的费用,请考虑使用remote testing in Selenium cloud,到目前为止,支持的Chrome版本从43到67,其中包括60-62的子范围。