Most basic Selenium webdriver "Hello World" fails miserably - ruby-on-rails

My selenium webdriver 'hello world' program is error-ing. Apologies since I am very new to this.
I spun up a new Ubuntu image and here is my setup:
Ubuntu 18.04 with Google Chrome installed
Ruby on Rails
selenium-webdriver gem installed
VNC is installed
My 'hello world' program:
require "selenium-webdriver"
**driver = Selenium::WebDriver.for :chrome**
driver.navigate.to "http://www.google.com"
element = driver.find_element(:name, 'q')
element.send_keys "Hello Selenium WebDriver!"
element.submit
puts driver.title
This spits out the error:
/home/user/.rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/response.rb:72:in `assert_ok': unknown error: Chrome failed to start: exited abnormally (Selenium::WebDriver::Error::UnknownError)
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 5.0.0-1028-gcp x86_64)
(This error happens at the boldfaced line of code)
I checked with whereis command for google-chrome and google-chrome-stable. They are both in /usr/bin/
I also have VNC installed and I am looking at the operating system. When I run this program, I am hoping for Chrome to pop out but nothing happens.
Is Selenium supposed to start chrome (visible to me in VNC)? In any case, what am I doing wrong?

A few things can be going wrong here.
First things first, make sure you have an up-to-date copy of chromedriver installed on the machine. You can extract and place the executable in any location that's included in $PATH (echo $PATH to see where these directories are located).
If you're still having issues, it's worth trying to add the following options to the driver initialization, like this:
options = Selenium::WebDriver::Chrome::Options.new
options.headless!
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = Selenium::WebDriver.for :chrome, options: options
If that works for you, this may be an issue related to the x window manager that's installed (or not installed). Alternatively to messing around with something like that, you could check out XVFB to run selenium tests in.

Related

Why does upgrading chome and chrome driver stop web application from loading

Im Running E2E testing on a web application in Jenkins using a centos node with webdriver IO.
Chrome :google-chrome-stable-96.0.4664.110-1.x86_64.rpm
Chrome driver:
sh 'sudo yum info google-chrome-stable | grep Version > chromeOutFile'
def CHROME_VERSION = readFile('chromeOutFile')
def Version = CHROME_VERSION.split('Version :')
def VersionNumber = Version[1].trim()
sh "./src/main/web/node_modules/protractor/bin/webdriver-manager update --versions.chrome=${VersionNumber}"
Id like to update this to user the latest version of chrome with a corresponding chrome driver.
Webdriver IO config:
services: [['chromedriver', {
chromedriverCustomPath: '../node_modules/webdriver-manager/selenium/chromedriver_96.0.4664.110'
}]],
Problem: when I try to use a more upto date version, even if its chromedriver_97.0.4692.99, my web application no longer starts up in Jenkins. When I try to visit the url, the screen shot just shows a blank screen. Im not sure the application is even loading.
Why does it only work with 96 but not others?
I tried to map the version of chrome with an appropriate version of chrome driver using https://chromedriver.storage.googleapis.com/LATEST_RELEASE_97.0.4692 but that still doesnt work for me.
Running tests:
cd e2e && wdio run wdio.ci.conf.ts --suite access --logLevel=info
+ lsb_release -d
Description: CentOS Linux release 7.9.2009 (Core)
Thanks
Have you tried to check memory limits? I had a similar problem with automated testing and had to change memory limits to either 1) limit chrome's memory or 2) pre allocate a set amount of memory ahead of time from my webserver if you are testing on the same device.

Unable to find chrome binary in WSL while running Rails tests

I am trying to run integration tests for my Rails application in Windows Subsystem for Linux. I have downloaded the chromedriver file for windows from the official site and placed it in Documents/bin folder. I have added the following file in the same folder and saved it as chromedriver:
#!/bin/sh
chromedriver.exe "$#"
So presently Documents/bin folder has these two files: chromedriver.exe and chromedriver. I have added this folder to PATH in windows.
When I type chromedriver -v in Ubuntu terminal in Windows I get the following output:
ChromeDriver 75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770#{#1003})
But when I execute any Rails integration test I am getting the following error:
sh: 1: ["/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin", "/opt/google/chrome"]: not found
sh: 1: ["/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin", "/opt/google/chrome"]: not found
sh: 1: ["/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin", "/opt/google/chrome"]: not found
Webdrivers::VersionError: Failed to find Chrome binary or its version.
chrome version in windows: Version 75.0.3770.90 (Official Build) (64-bit)
So linux is able to find chromedriver but not rails. How can I rectify this error? Should I run sudo apt-get install chromium chrome-driver? Or is there another method to make rails know the path to chromedriver binary?
You need to add the path to your chrome.exe to the PATH environment variable in Ubuntu

Chromedriver crashes once running with Jenkins

I have created Web test using Robotframework.
Once I am trying to run test with Jenkins, the test fails due to chromedriver crash on start. This is the message I receive:
WebDriverException: Message: unknown error: Chrome failed to start: crashed
(Driver info: chromedriver=2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b),platform=Mac OS X 10.12.4 x86_64)
Attempt to run it manually succeed, everything works fine.
This is a reduced code I am running:
*** Test Cases ***
Test Sanity Setup
[Tags] Sanity
${chrome_options} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
${prefs} Create Dictionary credentials_enable_service=${false}
Call Method ${chrome_options} add_experimental_option prefs ${prefs}
Call Method ${chrome_options} add_argument --disable-infobars
Call Method ${chrome_options} add_argument --kiosk
Create WebDriver Chrome chrome_options=${chrome_options}
Go to URL
Go To ${URL}
Finalize Tests
close all browsers
*** Keywords ***
Provided precondition
Setup chromedriver
Set Environment Variable webdriver.chrome.driver ./driver/chromedriver.exe
Could you please elaborate on what OS you are having Jenkins run this test? The code suggests your local machine is Windows, since you are setting the webdriver.chrome.driver to a Windows .exe? This will not work on Linux and Mac machines.
A manual for running Headless Chrome on Linux and Windows can be found here.
PS: Headless Chrome is coming to Linux and Mac very soon in Chrome 59, but it will take a little more time before Selenium and the Selenium-chrome-driver also support it.

EOFError: end of file reached -- all js specs are crashing Capybara with an older Chrome driver

Capybara using Chrome driver with setup:
spec_helper
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Capybara.javascript_driver = :chrome
I appear to be getting
EOFError:
end of file reached
On all of my Javascript tests when I run them with chrome driver.
This appears to have began on or around Oct 27, 2016
Running with poltergeist they work fine.
• also when they crash they appear to open multiple instances of chrome which hang (but do not exit) see http://screencast.com/t/Worwl9d6Iuhr screenshot example
• these appear to affect only my javascript specs (:js => true in Capybara)
• Rebooting my machine did not solve the problem
• My Chrome Mac OS X is currently at 54.0.2840.71
• I'm not sure when sub-sub-point version 71 got released since of course Chrome doesn't tell you or even seem to have it available in some kind of update history. The public information says sub-point version 54.0.2840 was released 2016-10-12 but it doesn't specify when sub-sub-point version 71 was released
• I can reproduce the effect on both my code on master, as well, I have a specific memory of running these specs with Chrome driver earlier in this week, so I am strongly suspecting that Chrome did a sub-sub-point release here and broke this.
if anyone else can confirm I would appreciate it. otherwise, if I find a local problem, I will post answer here.
• Capybara 2.7.1
• selenium-webdriver 2.53.0
• I located the Chromedriver executable in my machine at /usr/local/bin/chromedriver [is this the right one -- I seem to have an older one in /Users/jason/bin/chromedriver ?]
$ which chromedriver
/usr/local/bin/chromedriver
$ /usr/local/bin/chromedriver -v
ChromeDriver 2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b)
Upgrading Chrome Driver to 2.25 solved the issue
to do so via brew
$ brew unlink chromedriver
Unlinking /usr/local/Cellar/chromedriver/2.20... 1 symlinks removed
$ brew install chromedriver
==> Using the sandbox
==> Downloading https://chromedriver.storage.googleapis.com/2.25/chromedriver_mac6
######################################################################## 100.0%
==> Caveats
To have launchd start chromedriver now and restart at login:
brew services start chromedriver
Or, if you don't want/need a background service you can just run:
chromedriver
==> Summary
🍺 /usr/local/Cellar/chromedriver/2.25: 4 files, 10.3M, built in 7 seconds
hope this helps someone. I recently got this error when I was using capybara/poltergeist on a specific port (`., then I had a crashed test process still listening on a specific port.
If you are using rbenv, you can upgrade the chromedriver using brew than copy the executable :
for example, I'm using ruby 2.4.1:
$ cp /usr/local/Cellar/chromedriver/2.30/bin/chromedriver $HOME/.rbenv/versions/2.4.1/bin/
$ chmod +x $HOME/.rbenv/versions/2.4.1/bin/chromedriver
thank you

Unable to get chrome driver working through jenkins

I am unable to get chrome driver working via Jenkins. My tests run fine from a terminal window but I wish to run them from Jenkins in headless mode.
I have the latest recommended version of chrome driver installed and Chrome version 28.0.1500.71. Chromedriver has been placed on my path at /Usr/bin.
However when I attempt to run the tests from Jenkins I get an error message:
"Unable to either launch or connect to Chrome. Please check that ChromeDriver is up-to-date. Using chrome binary at: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome (Selenium::WebDriver::Error::UnknownError)"
I have also tried installing previous version of chrome and chromedriver but I get the same error message.
So after some investigation I found that in order to run headless tests via Jenkins you may need to have installed xvfb. (i say may because I am not 100% sure if this is correct) So I installed xvfb via Xquartz and the xvfb file is also on my path at /Usr/bin.
However even after doing the above with Xvfs I still get the error. Xvfs appears to start successfully as I get the message: Xvfb starting$ /Usr/bin/Xvfb :1 -screen 0 1024x768x24 -fbdir /Users/Shared/Jenkins/Home/2013-07-15_16-24-193595155347701391882xvfb in the console output in Jenkins.
Anybody have any idea what I am doing wrong? I am new to the world of Macs so there may be something I am missing.
Any help would be greatly appreciated!!
Managed to get this sorted. Instead of enabling Xvfb in the job configuration build environment section, I ran it using a terminal command and it now works. So my terminal command is now: xvfb-run cucumber --tags #automated - So this issue can be closed

Resources