Chromedriver crashes once running with Jenkins - 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.

Related

Most basic Selenium webdriver "Hello World" fails miserably

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.

Network based run is getting directed to Local 127.0.0.1

We're running wdio tests using wdio (both for local run & browserstack based devices)
When I run browserstack (server run) I am getting following error:
[11:41:04] COMMAND POST "/wd/hub/session"
[11:41:04] DATA {"desiredCapabilities":{"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"name":"Ping","build":"1.0","browserstack.debug":true,"device":"Samsung Galaxy S8","os_version":"7.0","requestOrigins":{"url":"http://webdriver.io","version":"4.14.2","name":"webdriverio"}}}
ERROR: connect ECONNREFUSED 127.0.0.1:4444
My dependency stack
We use yarn
"wdio-allure-reporter": "0.8.3",
"wdio-appium-service": "^0.2.3",
"wdio-browserstack-service": "^0.1.18",
"wdio-cucumber-framework": "2.2.8",
"wdio-dot-reporter": "0.0.10",
"wdio-mocha-framework": "^0.6.4",
"wdio-screenshots-cleanup-service": "0.0.7",
"wdio-spec-reporter": "^0.1.4",
"wdio-visual-regression-service": "^0.9.0",
"webdriverio": "4.14.2"
I have tried troubleshooting tip mentioned on below documentation, but no affect.
Kindly advise what might be the reason tests are not running either locally & not on server.
Troubleshooting tip
The error you're seeing is because wdio is trying to reach out to a WebDriver server on "127.0.0.1:4444", which is the default local server (i.e. not Browserstack).
This means you likely don't have your user/key set up in your wdio.conf.js file. WebdriverIO relies on the user/key to determine what default server to use.
Check your config that both user and key are set. More info is available here:
http://v4.webdriver.io/guide/services/browserstack.html

How to start Appium server programatically in mac using ruby ?

Is there a way I can get appium to startup within the code? I am trying to automate an iOS application, Since appium only needs to run when my test is running it doesnt make sense to me to keep the appium server always going.
Right now I am using Appium GUI to start server.Is it possible to add something in Before method to start the appium server before connecting the WebDriver to it, and then terminating it in the After method.
Please help me to do it in Mac using Ruby.
Appium server version: 1.8.0
Mac OS: 10.13
node: 6.11
Ruby: 2.5.1
Thanks in advance,
Here is solution for BDD framework written Ruby. Paste these two hooks in hooks.rb file
Starting the server:
AfterConfiguration do |config|
pid = spawn ‘appium --address 0.0.0.0 --port 4723’
Process.detach(pid)
sleep(10)
end
AfterConfiguration hook that will be run after Cucumber has been configured. This hook will run only once,after support has been loaded but before features are loaded. so it is usefull to launch Appium server.
Stoping the server:
at_exit do
exec ‘/usr/bin/killall -KILL node’
end
at_exit will be executed after execution of all the feature files. So executing exec '/usr/bin/killall -KILL node' command inside this hook kills the server at the end
call shell commands from inside of a Ruby program.
`/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js --address 127.0.0.1 --chromedriver-port 9516 --bootstrap-port 4725 --selendroid-port 8082 --no-reset --local-timezone`
change the path accordingly or copy the appium app to Applications folder

Unable to run functional tests on server. [geb spock]

Hi I am running my functional tests using geb.
I am able to run tests on my local computer correctly. but as I deploy my application to server. the build for functional tests fails.
Here is my console output
|Running 10 spock tests... 1 of 10
Failure: |
sign in with voucher
|
geb.driver.DriverCreationException: failed to create driver from callback 'script14007213321291157436758$_run_closure1#77068fce'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:346)
at geb.Configuration.getDriver(Configuration.groovy:335)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.go(Browser.groovy:377)
at geb.Page.to(Page.groovy:171)
at geb.Browser.via(Browser.groovy:454)
at geb.Browser.to(Browser.groovy:413)
at geb.Browser.to(Browser.groovy:391)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:51)
at VoucherSpec.sign in with voucher(VoucherSpec.groovy:14)
Caused by: org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/usr/local/bin/firefox) on port 7056; process output follows:
Error: no display specified
Error: no display specified
Can anyone guide me to solve this issue.
The server you're running the tests on is 'headless' so doesn't have a display to start Firefox on to run the tests. You've got a couple of options:
Switch from Firefox to a headless browser such as HTMLUnit.
Configure a virtual display on the server.
Use a remote browser service such as SauceLabs.
If you need to test directly on Firefox then HTMLUnit isn't an option for you.
Using a remote browser service such as SauceLabs or BrowserStack has a couple of advantages, for example they record a video of the session and take screenshots, but we found the overhead of passing commands & traffic over the network made the tests unacceptably slow. If you need to test a wide variety of browsers then the overhead diminishes because you can run in parallel...
Option 2, using a virtual display, is the simplest to configure on most servers. If you're using Linux the X Virtual Frame Buffer (XVFB) will get you up and running quickly. It's worth reading up on what's going on but the short answer is:
Install XVFB (sudo apt-get install xvfb)
Install Firefox (sudo apt-get install firefox)
Start XVFB (sudo Xvfb :10 -ac -screen 0 1024x768x8 &). You may want to add an init script so this happens every time the server starts
In your CI server add export DISPLAY=:10 as a step before the tests are run
Run your tests
The XVFB creates a virtual display on :10, which you then set as the default display. When you start Firefox it's completely unaware that it's on a virtual display, so things like getting Geb to take screenshots of failing tests will work as normal.
For more information about the steps see:
http://www.installationpage.com/selenium/how-to-run-selenium-headless-firefox-in-ubuntu/
https://github.com/tomaslin/grails-test-recipes
http://www.semicomplete.com/blog/geekery/xvfb-firefox.html
http://www.labelmedia.co.uk/blog/setting-up-selenium-server-on-a-headless-jenkins-ci-build-machine.html
http://manpages.ubuntu.com/manpages/lucid/man1/xvfb-run.1.html
If you need an init script to get it to start/stop, then there are quite a few to choose from, such as this one.

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