Linux Jenkins显示无法访问的错误
当我在Linux上执行测试时,我遇到了以下问题:Linux Jenkins显示无法访问的错误,linux,jenkins,selenium-chromedriver,Linux,Jenkins,Selenium Chromedriver,当我在Linux上执行测试时,我遇到了以下问题: org.openqa.selenium.WebDriverException: chrome not reachable (Session info: headless chrome=67.0.3396.99) (Driver info: chromedriver=2.40.565383 platform=Linux 4.14.33-51.34.amzn1.x86_64 x86_64) (WARNING: The server did not
org.openqa.selenium.WebDriverException: chrome not reachable
(Session info: headless chrome=67.0.3396.99)
(Driver info: chromedriver=2.40.565383
platform=Linux 4.14.33-51.34.amzn1.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
这些测试在通过命令行执行时运行良好。我安装了jenkins并设置了一些作业,然后开始使用jenkin作业执行相同的测试。在设置jenkins之后,我得到了上面的错误,当前通过命令行执行的测试也显示了相同的错误
Jenkins作为war文件安装,并从非root用户使用nohup命令启动
下面是web驱动程序初始化的代码
public static WebDriver getDriver(){
//Get the current OS Version
String os = System.getProperty("os.name").toLowerCase();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("window-size=1920x1080");
//Execute Headless if on Test Server
if(os.contains("linux")) {
System.setProperty("webdriver.chrome.driver", "path to chromedriver");
chromeOptions.addArguments("--headless");
//Option added to resolve chrome not reachable issue
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("--disable-setuid-sandbox");
chromeOptions.addArguments("--disable-gpu");
}
webdriver = new ChromeDriver(chromeOptions);
return webdriver;
}
这在Mac上运行的本地计算机上不会出现问题
任何帮助都将不胜感激。由于这个原因,我一直在找Jenkins的工作
卸载Jenkins后,命令行执行再次开始正常工作。这与Jenkins的安装有关吗?请尝试以下代码
public static WebDriver getDriver(){
//Get the current OS Version
String os = System.getProperty("os.name").toLowerCase();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("window-size=1920x1080");
//Execute Headless if on Test Server
if(os.contains("linux")) {
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("start-maximized");
chromeOptions.addArguments("disable-infobars");
chromeOptions.addArguments("--disable-extensions");
System.setProperty("webdriver.chrome.driver", "path to chromedriver");
}
webdriver = new ChromeDriver(chromeOptions);
return webdriver;
}
在我看来,问题在于Linux和Jenkins中chromeoptions中无头chrome的分辨率设置。通过差异分辨率和结果将有所不同。尝试了以下方法,现在我得到了100%准确的结果
File file = new File("/usr/bin/chromedriver");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
options.addArguments("window-size=1280x800");
options.addArguments("no-sandbox");
options.addArguments("–disable-dev-shm-usage");
options.addArguments("start-maximized");
options.addArguments("--disable-gpu");
options.addArguments("--disable-setuid-sandbox");
driver = new ChromeDriver(options);
使用上述代码进行了尝试,但仍然没有成功。继续获取相同的问题您的chrome驱动程序是否可执行?同时检查chrome驱动程序的路径chrome驱动程序是否可执行以及路径是否正确。这在之前通过命令行执行时运行良好。安装Jenkins后开始出现错误