简体   繁体   English

使用 maven 和 WebDriverManager 在 Jenkins 上找不到 Chrome 二进制错误

[英]cannot find Chrome binary error on Jenkins using maven and WebDriverManager

I'm trying to run my test (Selenium+junit+cucumber+Maven) on Jenkins.我正在尝试在 Jenkins 上运行我的测试(Selenium+junit+cucumber+Maven)。 In my definition class I'm not pointing to Chrome binary but rather use WebDriverManager:在我的定义类中,我不是指向 Chrome 二进制文件,而是使用 WebDriverManager:

@Given("^I navigate to page$") @Given("^我导航到页面$")

public void i_navigate_to_webpage() throws Throwable {

    String url = Helper.getPropValue("landing", "navigation");

    WebDriverManager.chromedriver().setup();
    driver = new ChromeDriver();
    wait = new WebDriverWait(driver,20);

    driver.manage().window().maximize();
    driver.get(url);

}

It works fine on my machine (Win), but when I'm trying to execute this on Jenkins (Ubuntu box), I get error:它在我的机器 (Win) 上运行良好,但是当我尝试在 Jenkins (Ubuntu box) 上执行它时,出现错误:

org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary (Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.4.0-1047-aws x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 687 milliseconds Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06' System info: host: 'ip-172-31-12-150', ip: '172.31.12.150', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-1047-aws', java.version: '1.8.0_151' Driver info: org.openqa.selenium.chrome.ChromeDriver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote. org.openqa.selenium.WebDriverException:未知错误:找不到 Chrome 二进制文件(驱动程序信息:chromedriver=2.35.528139(47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.4.0-1047 没有提供任何堆栈:xWARING-1047N信息)命令持续时间或超时:687 毫秒构建信息:版本:'2.48.2',修订版:'41bccdd10cf2c0560f637404c2d96164b67d9d67',时间:'2015-10-09 13:08:172' 31-12-150', ip: '172.31.12.150', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-1047-aws', java.version: ' 1.8.0_151' 驱动程序信息:org.openqa.selenium.chrome.ChromeDriver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.AccessDelegating newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote。 ErrorHandler.createThrowable(ErrorHandler.java:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:170) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:159) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:116) at GridTest.grid.StepDef.i_navigate_to_webpage(StepDef.java:52) at ✽.Given I navigate to page(src/test/test.feature:6) ErrorHandler.createThrowable(ErrorHandler.java:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647) at org .openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247) 在 org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129) 在 org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDriver.RemoteWebDriver.) :142) 在 org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:170) 在 org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:159) 在 org.openqa.selenium.chrome.ChromeDriver。 (ChromeDriver.java:116) at GridTest.grid.StepDef.i_navigate_to_webpage(StepDef.java:52) at ✽.Given I navigation to page(src/test/test.feature:6)

I was under impression that WebDriverManager should have covered that how it does on my Windows machine.我的印象是 WebDriverManager 应该涵盖它在我的 Windows 机器上的表现。 Isn't it so?不是这样吗?

My Pom.xml file here:我的 Pom.xml 文件在这里:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>GridTest</groupId>
  <artifactId>grid</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>grid</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <suiteXmlFile>testing.xml</suiteXmlFile>
  </properties>
  <build>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        com.lazerycode.selenium
                                    </groupId>
                                    <artifactId>
                                        driver-binary-downloader-maven-plugin
                                    </artifactId>
                                    <versionRange>
                                        [1.0.17,)
                                    </versionRange>
                                    <goals>
                                        <goal>selenium</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20.1</version>
            </plugin>
        </plugins>
    </pluginManagement>
  </build>
    <dependencies>
    <dependency>
   <groupId>io.github.bonigarcia</groupId>
   <artifactId>webdrivermanager</artifactId>
    <version>2.1.0</version>
    </dependency>
    <dependency>
        <groupId>com.vimalselvam</groupId>
        <artifactId>cucumber-extentsreport</artifactId>
        <version>3.0.2</version>
    </dependency>
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>3.1.1</version>
    </dependency>
    <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.12</version>
         <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.2</version>
    </dependency>
   <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-core</artifactId>
    <version>1.2.2</version>
  </dependency>
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>2.48.2</version>
  </dependency>

  </dependencies>
</project>

Your chrome on Ubuntu is not installed into default location:您在 Ubuntu 上的 chrome 未安装到默认位置:

在此处输入图片说明

More detail更多细节

you can add the chrome binary to PATH environent variable or reinstall it to default location.您可以将 chrome 二进制文件添加到PATH变量或将其重新安装到默认位置。

Make sure chromedriver compatible with chrome browser, check this link to get compatible mapping确保 chromedriver 与 chrome 浏览器兼容,检查此 链接以获取兼容映射

Chromedriver 2.35 Supports Chrome v62-64

When run script from Linux terminal tunnel, like run by Jenkins.当从 Linux 终端隧道运行脚本时,比如由 Jenkins 运行。 In general, Linux terminal tunnel not have display screen, but run script with headful model require a physical or virtual display.通常,Linux 终端隧道没有显示屏幕,但使用 headful 模型运行脚本需要物理或虚拟显示。

Option 1: run with headless model when not setup virtual display by xWindow/xvbf选项 1:当没有通过 xWindow/xvbf 设置虚拟显示时,使用headless模型运行

ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
// Must maximize Chrome by `start-maximized`
options.addArguments("start-maximized");

//Dont maximize Chrome by below line, because has no display
driver.manage().window().maximize()

Option 2: run with headful model, but need setup virtual display for the user which Jenkins used to connect to your Ubuntu box or you setup for all users if you can't know which user.选项 2:使用headful模型运行,但需要为 Jenkins 用来连接到您的 Ubuntu 机器的用户设置虚拟显示,或者如果您不知道哪个用户,则为所有用户设置。

Please read document about Xvbf or other xWindow to setup virtual display.请阅读有关 Xvbf 或其他 xWindow 的文档来设置虚拟显示。

您可以在 Jenkins 的构建设置中设置 chrome 路径作为目标:

-Dselenide.browserBinary="chrome/path_to_exe"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jenkins 未知错误:找不到 Chrome 二进制文件 - Jenkins unknown error: cannot find Chrome binary Jenkins:管道错误 - 找不到 Chrome 二进制文件 - Jenkins : pipeline error - cannot find Chrome binary CreatePlatformSocket() 失败:协议不支持地址系列,并且无法在 AWS Lambda 中使用 WebDriverManager 找到 chrome 二进制文件 - CreatePlatformSocket() failed: Address family not supported by protocol and cannot find chrome binary using WebDriverManager in AWS Lambda webdrivermanager 安装的 chrome 二进制文件不起作用 - chrome binary installed by webdrivermanager is not working Jenkins Maven 编译错误找不到符号 - Jenkins Maven compilation error cannot find symbol Windows + Selenium + Chrome =未知错误:找不到Chrome二进制文件 - Windows+Selenium+Chrome=unknown error: cannot find Chrome binary 错误:找不到Chrome二进制文件-Selenium OSX Java Eclipse - error: cannot find Chrome binary - Selenium OSX java Eclipse 使用 WebDriverManager 时如何设置 Chrome 选项? - How to set Chrome Options when using WebDriverManager? Mac + Selenium + Chrome =找不到Chrome二进制文件 - Mac + Selenium + Chrome = cannot find Chrome binary 詹金斯建立找不到资源,但行家 - Jenkins build cannot find resources but maven does
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM