我正在 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
我尝试了@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 中的文档安装并使用最新的google-chrome使用 Yum 您需要遵循以下顺序:
- 打开终端应用程序。获取 64 位 Google Chrome 安装程序。
键入以下命令下载 64 位版本的 Google Chrome:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
在 CentOS/RHEL 上安装 Google Chrome 及其依赖项,输入:
sudo yum install ./google-chrome-stable_current_*.rpm
从 CLI 启动 Google Chrome:
google-chrome &
yum 命令的输出:
最后,您需要使用以下行来设置 chrome 二进制文件:
options.setBinary("/usr/bin/google-chrome");
其他注意事项
确保:
- 以非root用户身份执行
@Test
。 - 始终在
tearDown(){}
方法中调用driver.quit()
来关闭和销毁 WebDriver 和 Web Client 优雅地实例化。
引用
您可以在以下位置找到一些相关讨论:
关于linux - WebDriver异常: no chrome binary at/usr/bin/google-chrome-stable or chrome binary not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62233719/