org.openqa.selenium.WebDriverException:未知错误:Chrome无法启动:在Ubuntu 18.04上的Jenkins中使用ChromeDriver Selenium导致崩溃 [英] org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: crashed using ChromeDriver Selenium in Jenkins on Ubuntu 18.04

查看:158
本文介绍了org.openqa.selenium.WebDriverException:未知错误:Chrome无法启动:在Ubuntu 18.04上的Jenkins中使用ChromeDriver Selenium导致崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chrome在我的Jenkins上不稳定.当我运行5次构建时,它运行1-2次成功,而其他3次出现上述错误.

Chrome is not stable on my Jenkins. When I run build 5 times, it runs 1 - 2-time success, and the other 3 times I have the above error.

错误快照:

Chrome代码:

ChromeOptions options = new ChromeOptions();
System.setProperty("webdriver.chrome.driver","/usr/local/bin/chromedriver");
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
driver = new ChromeDriver(options);
driver.get("https://mywebsite.com");
     

我已经采取了一些步骤:

Some steps I have already taken :

  1. 为Google chrome和chrome驱动程序提供777权限

  1. Provided 777 permission to google chrome and chrome driver

Set:在Jenkins构建设置中,在构建之前启动Xvfb,并在将其设置为True之后将其关闭

Set : Start Xvfb before the build, and shut it down after to True in Jenkins build setting

ChromeDriver 81.0.4044.69

ChromeDriver 81.0.4044.69

Google Chrome 81.0.4044.129

Google Chrome 81.0.4044.129

Ubuntu 18.04.4 LTS(GNU/Linux 4.15.0-99-通用x86_64)

Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-99-generic x86_64)

推荐答案

此错误消息...

...表示 ChromeDriver 无法启动/产生新的浏览上下文,即 Chrome浏览器会话.

...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.

尽管您提到了有关使用 ChromeDriver 81.0.4044.69 Google Chrome 81.0.4044.129 的信息,但查看了所提供的错误堆栈跟踪的快照,但似乎仍然存在您正在使用的不同二进制文件的版本之间不匹配,可能是系统中的默认位置未安装 Chrome 浏览器,或者是由于JDK不匹配.此外, ChromeDriver 81.0.4044.69(2020-03-17)有点不稳定,由

Looking into the snapshot of the error stacktrace you have provided, though you mentioned about using ChromeDriver 81.0.4044.69 and Google Chrome 81.0.4044.129, still it appears there is a mismatch between the versions of the different binaries you are using, possibly Chrome browser is not installed at the default location within your system or due to JDK mismatch. Additionally, ChromeDriver 81.0.4044.69 (2020-03-17) was a bit unstable which was replaced by ChromeDriver 81.0.4044.138 (2020-05-05)

但是,服务器(例如 ChromeDriver )希望您按照以下图片在每个系统的默认位置中安装 Chrome :

However, the server i.e. ChromeDriver expects you to have Chrome installed in the default location for each system as per the image below:

1 对于Linux系统,ChromeDriver希望/usr/bin/google-chrome是实际Chrome二进制文件的符号链接.

1For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.

您可以在


解决方案

如果您在非标准位置使用 Chrome 可执行文件,则必须覆盖Chrome二进制位置,如下所示:


Solution

In case you are using the Chrome executable in a non-standard location you have to override the Chrome binary location as follows:

  • 基于代码的解决方案:

  • Code based solution:

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
ChromeOptions options = new ChromeOptions();
options.setBinary('/usr/bin/google-chrome');    //chrome binary location
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com/");
//execute the remaining steps
driver.quit();

  • 其他注意事项-确保满足以下条件:

  • Additional considerations- Ensure the following:

    • JDK is upgraded to current levels JDK 8u251.
    • Selenium is upgraded to current levels Version 3.141.59.
    • ChromeDriver is updated to current ChromeDriver v81.0.4044.138 level.
    • Chrome is updated to current Chrome Version 81.0.4044.138 level. (as per ChromeDriver v80.0 release notes)
    • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
    • Execute your @Test as non-root user.
    • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

    您可以在以下位置找到一些相关的讨论:

    You can find a couple of relevant discussions in:

    • WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
    • How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium?
    • Running Chromedriver on Ubuntu Server headlessly

    这篇关于org.openqa.selenium.WebDriverException:未知错误:Chrome无法启动:在Ubuntu 18.04上的Jenkins中使用ChromeDriver Selenium导致崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆