org.openqa.selenium.WebDriverException:未知错误:Chrome无法启动:在Jenkinson Ubuntu 18.04中使用ChromeDriver Selenium导致崩溃 - java

Chrome在我的Jenkins上不稳定。当我运行5次构建时,它运行1-2次成功,而其他3次出现上述错误。
错误快照:
org.openqa.selenium.WebDriverException:未知错误:Chrome无法启动:在Jenkinson Ubuntu 18.04中使用ChromeDriver Selenium导致崩溃 - java
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");
     

我已经采取的一些步骤:

  • 向Google chrome和chrome驱动程序提供777权限
  • Set:在构建之前启动Xvfb,然后在Jenkins构建设置中将其关闭为True
    org.openqa.selenium.WebDriverException:未知错误:Chrome无法启动:在Jenkinson Ubuntu 18.04中使用ChromeDriver Selenium导致崩溃 - java
  • ChromeDriver 81.0.4044.69
  • Google Chrome 81.0.4044.129
  • Ubuntu 18.04.4 LTS(GNU / Linux 4.15.0-99-通用x86_64)
  • 参考方案

    此错误消息...

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

    深潜

    查看您提供的错误stacktrace的快照,尽管您提到了有关使用ChromeDriver 81.0.4044.69和Google Chrome 81.0.4044.129的信息,但您似乎仍在使用不同二进制文件的版本之间存在不匹配,可能是Chrome浏览器是未安装在系统的默认位置或由于JDK不匹配而导致。此外,ChromeDriver 81.0.4044.69(2020-03-17)有点不稳定,已由ChromeDriver 81.0.4044.138 (2020-05-05)取代

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

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

    您可以在What is default location of ChromeDriver and for installing Chrome on Windows中找到详细的讨论

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

  • 基于代码的解决方案:
    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();
    
  • 其他注意事项-确保满足以下条件:
  • JDK已升级到当前级别JDK 8u251
  • Selenium已升级到当前级别Version 3.141.59。
  • ChromeDriver已更新为当前ChromeDriver v81.0.4044.138级别。
  • Chrome已更新为当前的Chrome版本81.0.4044.138。 (按照ChromeDriver v80.0 release notes)
  • 通过IDE清洁项目工作区,并仅使用必需的依赖项重建项目。
  • 非root 用户身份执行@Test
  • 始终在driver.quit()方法中调用tearDown(){}以优雅地关闭和销毁WebDriver和Web Client实例。
  • 参考文献

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

  • 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:未知错误:DevToolsActivePort文件不存在 - java

    我尝试在作为节点连接到硒网格的远程PC上启动电子应用程序。以前它可以正常工作。但是现在我收到此错误“ DevToolActivePort文件不存在” System.out.println("launch application in windows PC"); capa = new DesiredCapabilities(); capa.…

    Selenium Webdriver(Java)-查找禁用了属性=“”的元素 - java

    我有<input id="test" disabled="">。如何找到具有属性disable =“”的元素。附言:在这种情况下,我不需要使用ID。我想找到一个具有禁用属性的元素。我尝试使用String enbl = Login.driver.findElement(By.cssSelector("…

    NoSuchMethodError:org.openqa.selenium.support.ui.WebDriverWait.until - java

    我正在尝试运行以下硒代码: WebDriver driver; System.setProperty("webdriver.chrome.driver", "C:\\Driver\\chromedriver.exe"); driver = new ChromeDriver(); driver.get("htt…

    Selenium Grid显示WebDriverException错误 - java

    我的Selenium网格显示错误:org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.chrome.driver system property;但我已经完美地指定了它(据我所知)System.out.pr…

    等效于C#中的ASM类(Java) - java

    我的任务是将项目转换,同时将其升级,从Java转换为C#。但是,我发现以下类及其功能存在问题:import jdk.internal.org.objectweb.asm.tree.AbstractInsnNode; import jdk.internal.org.objectweb.asm.tree.ClassNode; import jdk.interna…