2

I am executing selenium test via Jenkins server in AWS Ubuntu.

I was getting chrome binary not found error so I set chrome binary in my code.

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);

Then the error changed to: no chrome binary at /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

This is how my usr/bin is: binary folders

And this is message when I try to launch browser in command line: launch chrome

I tried the solution given by @DebanjanB at Cannot find Chrome binary with Selenium in Python for older versions of Google Chrome but no luck. Any help is much appreciated as I have spent 2 days on this already.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Afsal
  • 404
  • 3
  • 7
  • 24

3 Answers3

2

Not sure if setBinary() should be pointing to /usr/bin/google-chrome-stable.

As per the documentation in How To Install Google Chrome 78 On a RHEL/CentOS 7 and Fedora Linux to install and use the latest using Yum you need to follow the sequence below:

  1. Open the Terminal application. Grab 64bit Google Chrome installer.
  2. Type the following command to download 64 bit version of Google Chrome:

    wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
    
  3. Install Google Chrome and its dependencies on a CentOS/RHEL, type:

    sudo yum install ./google-chrome-stable_current_*.rpm
    
  4. Start Google Chrome from the CLI:

    google-chrome &
    

Outputs from yum command:

yum-google-chrome-command

Finally, you need to use the following line to set the chrome binary:

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

Additional Considerations

Ensure that:

  • Execute your @Test as non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • install instructions you provided is fro rpm based systems. Mine is Ubuntu which uses deb installation. I followed: https://itsfoss.com/install-chrome-ubuntu/#install-chrome-terminal adding force install to get all dependencies. I tried options.setBinary("/usr/bin/google-chrome"); but error remains the same. I found I am unable to open chrome from CL but as root user it is working: – Afsal Jun 07 '20 at 07:15
  • root@jenkins-it02:~# google-chrome [15489:15489:0607/070913.642463:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180. root@jenkins-it02:~# exit logout – Afsal Jun 07 '20 at 07:15
  • qa_user@jenkins-it02:~$ google-chrome WARNING:root:could not open file '/etc/apt/sources.list.d/google.list' WARNING:root:could not open file '/etc/apt/sources.list.d/s3tools.list' WARNING:root:could not open file '/etc/apt/sources.list.d/google-chrome.list' WARNING:root:could not open file '/etc/apt/sources.list.d/jenkins.list' google-chrome: command not found qa_user@jenkins-it02:~$ – Afsal Jun 07 '20 at 07:15
  • Does this mean I can spawn chrome using root but not as qa_user? My jenkins is set up as qa_user. This is the root cause I arrived at after a lot of debugging but I still don't know how to fix it. – Afsal Jun 07 '20 at 07:17
  • UPDATE: I solved the 'could not open file' issue by giving permission to /etc/apt/sources.list.d for qa_user. Now the issue is I am unable to open chrome in CL. qa_user@jenkins-it02:~$ whereis google-chrome google-chrome: /usr/bin/google-chrome /usr/share/man/man1/google-chrome.1.gz qa_user@jenkins-it02:~$ google-chrome google-chrome: command not found qa_user@jenkins-it02:~$ Same command as root user gives: Running as root without --no-sandbox is not supported. See https://crbug.com/638180. – Afsal Jun 07 '20 at 07:43
0

I did not have the actual fix for this issue but I could get around my actual blocker by installing Chromium instead of Chrome. Difference I found is the installation directory of both.

I installed Chrome and whereis Google-Chrome-Stable gives:

qa_user@jenkins:~$ whereis google-chrome-stable google-chrome-stable: /usr/bin/google-chrome-stable /usr/share/man/man1/google-chrome-stable.1.gz

And qa_user@jenkins:~$ google-chrome-stable gives: google-chrome-stable: command not found

Now for Chromium:

qa_user@jenkins:~$ whereis chromium-browser gives: chromium-browser: /usr/bin/chromium-browser /usr/lib/chromium-browser /etc/chromium-browser /usr/share/chromium-browser /usr/share/man/man1/chromium-browser.1.gz

and qa_user@jenkins~$ chromium-browser [21304:21304:0607/135202.629230:ERROR:browser_main_loop.cc(1473)] Unable to open X display. Identifies and opens Chromium (X display issue can be solved by adding --headless option in actual Selenium code).

So I am gonna use Chromium instead of Chrome until I/Someone here find the fix for the actual Chrome issue here.

Afsal
  • 404
  • 3
  • 7
  • 24
0

UPDATE: After my below solution, I uninstalled Chromium and kept only Chrome for further testing. Surprisingly, chrome issue got fixed. I am able to run tests in Chrome now. Not sure how this is happening but I think it has something to do with dependency package that comes with Chrome.

I know this is strange but installing Chrome and Chromium and then uninstalling Chromium worked for me.

Afsal
  • 404
  • 3
  • 7
  • 24