WebDriverException:在/ usr / bin / google-chrome-stable找不到chrome二进制文件或未找到chrome二进制文件

时间:2020-06-06 15:14:33

标签: linux selenium google-chrome jenkins selenium-chromedriver

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

我遇到未找到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天的时间了。

3 个答案:

答案 0 :(得分:0)

不确定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
  • 始终在driver.quit()方法内调用tearDown(){},以优雅地关闭和销毁 WebDriver Web Client 实例。

参考

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

答案 1 :(得分:0)

我没有针对此问题的实际修复程序,但可以通过安装Chromium而不是Chrome来解决实际的阻止程序。我发现的区别是两者的安装目录。

我安装了Chrome,Google-Chrome-Stable在哪里提供了

qa_user @ jenkins:〜$ where google-chrome-stable google-chrome-stable:/ usr / bin / google-chrome-stable /usr/share/man/man/man1/google-chrome-stable.1.gz < / p>

然后qa_user @ jenkins:〜$ google-chrome-stable给出:google-chrome-stable:找不到命令

现在要使用铬:

qa_user @ jenkins:〜$ where铬浏览器给出:铬浏览器:/ usr / bin / chromium-browser / usr / lib / chromium-browser / etc / chromium-browser / usr / share / chromium-browser / usr / share / man / man1 / chromium-browser.1.gz

和qa_user @ jenkins〜$铬浏览器[21304:21304:0607 / 135202.629230:ERROR:browser_main_loop.cc(1473)]无法打开X显示。识别并打开Chromium(可以在实际的Selenium代码中添加--headless选项来解决X显示问题)。

所以我要使用Chromium而不是Chrome,直到我/有人在这里找到解决实际Chrome问题的解决方法为止。

答案 2 :(得分:0)

更新: 在采用以下解决方案后,我卸载了Chromium,仅保留了Chrome进行进一步测试。令人惊讶的是,镀铬问题已得到解决。我现在可以在Chrome中运行测试。不确定这是怎么发生的,但我认为这与Chrome随附的依赖项软件包有关。

我知道这很奇怪,但是先安装Chrome和Chromium,然后再卸载Chromium即可。