【问题标题】:cannot find Chrome binary error on Jenkins using maven and WebDriverManager使用 maven 和 WebDriverManager 在 Jenkins 上找不到 Chrome 二进制错误
【发布时间】:2018-07-17 13:04:42
【问题描述】:

我正在尝试在 Jenkins 上运行我的测试(Selenium+junit+cucumber+Maven)。 在我的定义类中,我没有指向 Chrome 二进制文件,而是使用 WebDriverManager:

@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);

}

它在我的机器(Win)上运行良好,但是当我试图在 Jenkins(Ubuntu 机器)上执行它时,我得到了错误:

org.openqa.selenium.WebDriverException:未知错误:找不到 Chrome 二进制文件 (驱动程序信息:chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.4.0-1047-aws x86_64)(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:687 毫秒 构建信息:版本:'2.48.2',修订:'41bccdd10cf2c0560f637404c2d96164b67d9d67',时间:'2015-10-09 13:08:06' 系统信息:主机:'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' 驱动程序信息:org.openqa.selenium.chrome.ChromeDriver 在 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在 java.lang.reflect.Constructor.newInstance(Constructor.java:423) 在 org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) 在 org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) 在 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647) 在 org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247) 在 org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129) 在 org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java: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) 在 GridTest.grid.StepDef.i_navigate_to_webpage(StepDef.java:52) 在✽。鉴于我导航到页面(src/test/test.feature:6)

我的印象是 WebDriverManager 应该已经涵盖了它在我的 Windows 机器上的作用。不是吗?

我的 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>

【问题讨论】:

    标签: java maven google-chrome selenium


    【解决方案1】:

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

    -Dselenide.browserBinary="chrome/path_to_exe"

    【讨论】:

      【解决方案2】:

      您在 Ubuntu 上的 chrome 未安装到默认位置:

      More detail

      您可以将 chrome 二进制文件添加到 PATH 环境变量或将其重新安装到默认位置。

      确保 chromedriver 与 chrome 浏览器兼容,检查此link 以获得兼容的映射

      Chromedriver 2.35 Supports Chrome v62-64

      当从 Linux 终端隧道运行脚本时,例如由 Jenkins 运行。 一般情况下,Linux 终端隧道没有显示屏幕,但运行带有 headful 模型的脚本需要物理或虚拟显示。

      选项 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()
      

      选项 2: 使用 headful 模型运行,但需要为 Jenkins 用来连接到您的 Ubuntu 机器的用户设置虚拟显示,或者您为所有用户设置 如果你不知道哪个用户。

      请阅读有关 Xvbf 或其他 xWindow 的文档以设置虚拟显示。

      【讨论】:

      • 非常感谢,安装在那里。现在收到另一个错误:org.openqa.selenium.WebDriverException:未知错误:Chrome 无法启动:异常退出(驱动程序信息:chromedriver=2.35.528139(47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.4.0-1047-aws x86_64)跨度>
      • 通过在 Jenkins 上设置 xvfb 也解决了这个问题,所以,非常感谢!
      猜你喜欢
      • 2018-02-10
      • 2020-05-20
      • 2018-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-09
      • 2019-10-06
      • 1970-01-01
      相关资源
      最近更新 更多