linux - WebDriver异常: no chrome binary at/usr/bin/google-chrome-stable or chrome binary not found

标签 linux selenium google-chrome jenkins selenium-chromedriver

我正在 AWS Ubuntu 中通过 Jenkins 服务器执行 selenium 测试。

我收到 chrome 二进制未找到错误,因此我在代码中设置了 chrome 二进制。

System.setProperty("webdriver.chrome.driver","/var/lib/jenkins/.m2/repository/webdriver/chromedriver/linux64/83.0.4103.39/chromedriver");    
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("applicationCacheEnabled", true);
ChromeOptions options = new ChromeOptions();
options.merge(capabilities);
options.setBinary("/usr/bin/google-chrome-stable");
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--remote-debugging-port=9222");
options.addArguments("--disable-infobars"); 
options.addArguments("--disable-dev-shm-usage"); //Linux 
options.addArguments("--disable-browser-side-navigation"); 
options.addArguments("--disable-gpu"); //Windows
options.addArguments("--disable-web-security");
driver = new ChromeDriver(options);

然后错误更改为:/usr/bin/google-chrome-stable 处没有 chrome 二进制文件

Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103@{#416}) on port 14665
Only local connections are allowed.
ChromeDriver was started successfully.
 INFO [main] (ControlCenter.java:108)- START
[ERROR] Tests run: 4, Failures: 1, Errors: 0, Skipped: 3, Time elapsed: 2.116 s <<< FAILURE! - in TestSuite
[ERROR] com.info.end2end.ExcelAccountToFusion.onTestSetup  Time elapsed: 2.032 s  <<< FAILURE!
org.openqa.selenium.WebDriverException: 
**unknown error: no chrome binary at /usr/bin/google-chrome-stable**
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'jenkins-it02', ip: '10.113.0.187', os.name: 'Linux', os.arch: 'amd64', os.version: '5.3.0-1019-aws', java.version: '11.0.7'
Driver info: driver.version: ChromeDriver

这就是我的 usr/bin 的样子: binary folders

这是当我尝试在命令行中启动浏览器时的消息: launch chrome

我尝试了@DebanjanB在 Cannot find Chrome binary with Selenium in Python for older versions of Google Chrome 给出的解决方案但没有运气。非常感谢您的帮助,因为我已经为此花费了 2 天的时间。

最佳答案

不确定 setBinary() 是否应指向 /usr/bin/google-chrome-stable

根据 How To Install Google Chrome 78 On a RHEL/CentOS 7 and Fedora Linux 中的文档安装并使用最新的使用 Yum 您需要遵循以下顺序:

  1. 打开终端应用程序。获取 64 位 Google Chrome 安装程序。
  2. 键入以下命令下载 64 位版本的 Google Chrome:

    wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
    
  3. 在 CentOS/RHEL 上安装 Google Chrome 及其依赖项,输入:

    sudo yum install ./google-chrome-stable_current_*.rpm
    
  4. 从 CLI 启动 Google Chrome:

    google-chrome &
    

yum 命令的输出:

yum-google-chrome-command

最后,您需要使用以下行来设置 chrome 二进制文件:

options.setBinary("/usr/bin/google-chrome");

其他注意事项

确保:

  • 非root用户身份执行@Test
  • 始终在 tearDown(){} 方法中调用 driver.quit() 来关闭和销毁 WebDriverWeb Client 优雅地实例化。

引用

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

关于linux - WebDriver异常: no chrome binary at/usr/bin/google-chrome-stable or chrome binary not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62233719/

相关文章:

c++ - 将程序链接到 Eclipse 中的 C++ 项目? Linux

linux:每隔一秒执行一次线程

linux - Linux 中的固件和驱动程序

java - Selenium WebDriver Java - 如何执行 "if exists, then click, else skip"?

javascript - 一个简单的 WebdriverIO - Mocha 测试不显示浏览器

google-chrome - 大源/缩小文件使 Chrome 开发者工具卡住

c - Windows fd_set 结构

java - Selenium 移动鼠标不适用于低分辨率

html - Div inside 按钮在 IE 中无法正常工作

google-chrome - Chrome 上的 Angular2 表格行组件以单列显示