WebDriverException:等待驱动程序服务器启动时超时,通过Java使用Selify ChromeDriver和Chromium出错
我正在尝试通过Selify-Java库实现页面登录。我使用的驱动程序是Chromium(Chrome的开源版本)。这个实现在Windows环境下运行得很好,但是当我通过Jenkins(Linux Box)运行这个实现时,驱动程序无法启动。我希望在实例化ChromeDriver时不会看到任何问题,并且它应该会开始时没有任何问题。
以下是Linux环境的详细信息。
- 浏览器和驱动程序:Chromium 73.0.3683.86 Fedora Project
- Linux盒驱动路径:/usr/bin/Chrome-Browser.sh
- Java版本:1.8.0_131
- 硒版本使用:3.14.0,并尝试使用最新的3.141.59
- 操作系统:Linux
我已确保并验证该文件具有Jenkins用户执行的完全权限。
我正在尝试的代码
String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
ChromeOptions options = new ChromeOptions();
if (OS.indexOf("win") >= 0) {
filePath = new File(properties.getChromeDriverPath()).getAbsolutePath();
System.setProperty("webdriver.chrome.driver", filePath);
} else if (OS.indexOf("nux") >= 0) {
File chromiumDriver = new File("/usr/bin/chromium-browser");
System.setProperty("webdriver.chrome.driver", chromiumDriver.getAbsolutePath());
}
options.setHeadless(true);
WebDriver chromeDriver = new ChromeDriver(options);
错误日志。
com.src.test.services.integration.test.AuthServicesTest > testAuthentication STANDARD_ERROR
org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'xyzJenkinsHost.test.corp', ip: '172.20.3.2', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-862.14.4.el7.x86_64', java.version: '1.8.0_131'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:193)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:179)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
com.src.test.services.integration.test.AuthServicesTest > testAuthentication STANDARD_ERROR
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:19154/status] to be available after 20002 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:188)
... 21 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:205)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:156)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
... 22 more
解决方案
File chromiumDriver = new File("/usr/bin/chromium-browser");
System.setProperty("webdriver.chrome.driver", chromiumDriver.getAbsolutePath());
您正在将webdriver.chrome.driver
系统属性设置为chromium-browser
的位置。相反,您必须将该属性设置为指向chromdriver
可执行文件所在的位置(您应该已将其下载到某个位置)。
相关文章