jenkins Web驱动程序异常:/usr/bin/google-chrome-stable中没有铬二进制文件,或者没有找到铬二进制文件

5t7ly7z5  于 2022-11-02  发布在  Jenkins
关注(0)|答案(3)|浏览(156)

我正在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中没有铬二进制文件

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:

当我尝试在命令行中启动浏览器时,出现以下消息:

我在Cannot find Chrome binary with Selenium in Python for older versions of Google Chrome尝试了@DebanjanB提供的解决方案,但没有运气。任何帮助都非常感谢,因为我已经花了2天的时间在这上面了。

bfrts1fy

bfrts1fy1#

不确定setBinary()是否应指向**/usr/bin/google-chrome-stable**。
根据How To Install Google Chrome 78 On a RHEL/CentOS 7 and Fedora Linux中的文档,要使用 Yum 安装和使用最新的google-chrome,您需要遵循以下顺序:
1.打开终端应用程序。获取64位Google Chrome安装程序。
1.键入以下命令以下载64位版本的Google Chrome:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

1.要在CentOS/RHEL上安装Google Chrome及其依赖项,请键入:

sudo yum install ./google-chrome-stable_current_*.rpm

1.从CLI启动Google Chrome:

google-chrome &

yum命令的输出:

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

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

其他注意事项

确保:

  • 非root用户身份执行@Test
  • 始终在tearDown(){}方法中调用driver.quit(),以正常关闭和销毁 WebDriverWeb Client 示例。

参考

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

  • 在Python中找不到旧版Google Chrome的Selenium Chrome二进制文件
hrirmatl

hrirmatl2#

我没有这个问题的实际修复程序,但我可以通过安装Chromium而不是Chrome来绕过我的实际阻止程序。我发现两者的不同之处在于安装目录。
我安装了Chrome浏览器,Google Chrome稳定版提供:
qa_user@jenkins:~$谷歌铬稳定版在哪里?/usr/bin/谷歌铬-稳定/usr/共享/man/man 1/谷歌铬-稳定. 1. gz
和qa_user@Jenkins:~$谷歌铬稳定给出:谷歌铬稳定:未找到命令
现在是铬:
qa_user@jenkins:~$在哪里是铬浏览器给出:铬浏览器:/usr/bin/chromium浏览器/usr/lib/chromium浏览器/etc/chromium浏览器/usr/共享/chromium浏览器/usr/共享/man/man 1/chromium浏览器. 1. gz
无法打开X显示。标识并打开Chromium(X显示问题可以通过在实际的Selenium代码中添加--headless选项来解决)。
因此,我将使用铬,而不是铬,直到我/有人在这里找到修复实际的铬问题在这里。

wgx48brx

wgx48brx3#

更新:在我下面的解决方案之后,我卸载了Chrome,只保留了Chrome进行进一步的测试。令人惊讶的是,Chrome的问题得到了修复。我现在可以在Chrome中运行测试了。不知道这是怎么发生的,但我认为这与Chrome附带的依赖包有关。
我知道这很奇怪,但是安装Chrome和Chromium,然后卸载Chromium对我很有效。

相关问题