通过 Jenkins 为 Maven 项目实现 Selenium 测试自动化

问题描述 投票:0回答:1

我正在尝试将 selenium 测试套件(Maven)与 jenkins 集成,并且我使用 chrome 无头浏览器,但面临如下错误。

[2114:2114:0905/122912.875011:ERROR:ozone_platform_x11.cc(239)] Missing X server or $DISPLAY
[2114:2114:0905/122912.875064:ERROR:env.cc(255)] The platform failed to initialize.  Exiting.
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

安装的 chrome 驱动程序和 google 二进制文件是相同的。

以下代码已在无头浏览器的 Drivermodule.java 文件中实现。

System.setProperty("webdriver.chrome.driver", "/usr/bin/google-chrome");
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
driver = new ChromeDriver(options);
driver.get("https://www.google.com");

我正在使用 Amazon Linux 2 服务器来运行 jenkins 节点。

maven selenium-webdriver jenkins headless-browser xserver
1个回答
0
投票
"webdriver.chrome.driver", "/usr/bin/google-chrome"

在上面的行中,看起来您正在设置浏览器路径而不是驱动程序路径。

您需要下载

chromedriver
linux
并设置其路径如下:

"webdriver.chrome.driver","/usr/bin/chromedriver"
© www.soinside.com 2019 - 2024. All rights reserved.