我正在尝试将 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 节点。
"webdriver.chrome.driver", "/usr/bin/google-chrome"
在上面的行中,看起来您正在设置浏览器路径而不是驱动程序路径。
您需要下载
chromedriver
的linux
并设置其路径如下:
"webdriver.chrome.driver","/usr/bin/chromedriver"