我正在使用 Boni Garcia 的 webdrivermanager 插件来安装驱动程序。当我使用它在本地执行时,一切正常,但是当我尝试通过 Jenkins 执行相同操作时遇到问题。详情如下:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.3.0</version>
</dependency>
现在,当我尝试通过 Jenkins 执行相同的 Maven 项目时,我遇到了问题。我的从机是 docker 机器。
起初,我尝试使用 webdrivermanager 来安装 chrome 驱动程序,但我收到错误消息,指出找不到二进制文件。
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
options.addArguments("start-maximized");
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver(options);
错误:
org.openqa.selenium.WebDriverException:
unknown error: cannot find Chrome binary
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 3.10.0-862.14.4.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
然后我尝试使用框架内的驱动程序。我将 chromedriver 文件保存在框架内的驱动程序文件夹中,然后尝试执行它,但仍然出现错误(不过这次是不同的错误)
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
options.addArguments("start-maximized");
System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver");
driver = new ChromeDriver(options);
错误:
Running TestSuite
/home/jenkins/workspace/Dental_EIEI_Angular/EIEI Test Jenkins/src/test/resources/drivers/chromedriver: /home/jenkins/workspace/Dental_EIEI_Angular/EIEI Test Jenkins/src/test/resources/drivers/chromedriver: cannot execute binary file
Apr 03, 2019 2:19:23 PM org.openqa.selenium.os.OsProcess checkForError
SEVERE: org.apache.commons.exec.ExecuteException: Process exited with an error: 126 (Exit value: 126)