Selenium+Jenkins+Chromedriver = WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally - selenium

I have problem with running my Selenium tests in Jenkins.
A result of execution is always:
WebDriverException: Message: unknown error: Chrome failed to start:
exited abnormally
My tests are written in Robot Framework and are using Chromium webdriver.
I'm setting needed paths in my command, which looks like this:
export PATH=$PATH:/usr/lib/chromium-browser; export PATH=$PATH:/usr/lib/chromium-browser/chromedriver; . /home/michal/robot_env/bin/activate; robot -L TRACE /home/michal/project_robot/tests
And when I run this command manually in terminal IT WORKS fine (Chromium starts automatically and the test goes on).
So the problem suppose to be in Jenkins. I have installed Xvfb plugin, but it didn't help.
Additionally, in /etc/init.d/jenkins I put these lines:
/usr/bin/X :0 vt7 -ac
export DISPLAY=:0
xhost +
And once again - nothing changed. What else should I set or check?

i got stuck same way.
The problem is that jenkins has it own user, called jenkins, and jenkins user cannot open the browser.
if you try to make "su jenkins" and then "chromium-browser" you obtain the display error.
That because you obtain this issue. The problem is not the webdriver, the problem is the user.
i removed the jenkins user created by jenkins and i createad a normal user called jenkins before installing jenkins.
then i installed jenkins.
now jenkins user can run the test (because it can open the browser) but jenkins itself will not load anymore.

Related

chromium-browser Error: [670] Failed to put Xlib into threaded mode

my original aim was to run a headless selenium webdriver on a Raspberry Pi 3 (rasbian). After hours and hours of failing, I make a step back and now I only try to run chromium-browser which needed for the webdriver.
There... I recognize some errors after execute:
sudo ./chromium-browser --headless --no-sandbox --disable-gpu --disable-extensions
Error-Stack:
--disable-quic --enable-tcp-fast-open --disable-gpu-compositing --ppapi-flash-path=/usr/lib/chromium-browser/libpepflashplayer.so --ppapi-flash-args=enable_stagevideo_auto=0 --ppapi-flash-version=
[1015/183516.617458:ERROR:browser_main_loop.cc(670)] Failed to put Xlib into threaded mode.
[1015/183516.625190:ERROR:gpu_process_transport_factory.cc(1029)] Lost UI shared context.
I search for solution in internet but I found no results.
Following I have to add:
-everything works fine if run the webdriver on my windows system
-I reproduce the error on two complete different raspberry Pi's
-I also try to run on a Raspbian virtual machine
-I try to run the webdriver with iceweasel and geckodriver with the result "Error: connection refused"
So I am out of ideas, thankful for any response.
For others who are still struggling to find a solution:
It seems that the issue is with diplay resource when running the program on a remote server having multiple display.
You may try setting the DISPLAY environment parameter
export DISPLAY=:1.0;

Error after executing selenium with Chrome

I'm trying to execute Selenium with Chrome on Ubuntu 16.04 and what I do is:
Xvfb :10 -screen 0 1366x768x24 -ac &
google-chrome --remote-debugging-port=92222
When I execute the previous command I got this error:
vagrant#smart:~$ [2207:2332:1118/135124.679982:ERROR:bus.cc(394)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
DevTools listening on ws://127.0.0.1:9222/devtools/browser/39519bf4-dad5-4557-86d7-29bde71ee025
(google-chrome:2207): LIBDBUSMENU-GLIB-WARNING **: Unable to get session bus: Unknown or unsupported transport 'disabled' for address 'disabled:'
[2207:2207:1118/135124.939100:ERROR:gpu_process_transport_factory.cc(980)] Lost UI shared context.
[1:8:1118/135125.063874:ERROR:command_buffer_proxy_impl.cc(100)] ContextResult::kFatalFailure: Shared memory region is not valid
I run the selenium command:
java -jar selenium-server-standalone-3.141.5.jar
And when I try to create a session manually through the url I got what I show in picture.
I'm trying to work with some test with codecpetion and yii2 but initially I can't because of that. I'm using the lastest version of all components and I was working perfectly until today. As well I have chromedriver. What is happening?. I am running in a vagrant box and I'm trying to test my application with codeception and I have tried to reinstall selenium and chrome and I got nothing, Thanks so much.
It is because of a conflict between chromedriver, selenium and chrome. Downgrading chrome, it's solved

Selenium and Jenkins, test suite works in commandline not on jenkins

I've got a Selenium stand alone server, I run a simple test suite with a simple test case in command line and it works, here is the command line :
java -jar D:\POC\selenium-server-standalone-2.45.0.jar -Dhttp.proxyHost=XXXX -Dhttp.proxyPort=8080 -Dhttp.proxyUser=XXXX -Dhttp.proxyPassword=XXXX -htmlSuite *firefox http://XXXXX D:\Users\XXXX\Desktop\test_selenium.html D:\Users\XXXX\Desktop\result_selenium.html -firefoxProfileTemplate "C:\Users\XXXXX\AppData\Roaming\Mozilla\Firefox\Profiles\1yd4vpna.selenium" -debug
The same command is used by jenkins to run the test, here is the selenium result file :
info: Starting test /selenium-server/tests/test_case_selenium.html
info: Executing: |open | /index.php/fr/ | |
warn: currentTest.recordFailure: Timed out after 30000ms
info: Executing: |clickAndWait | css=li.item-175.first > a.subMenuBtn > span | |
error: Element css=li.item-175.first > a.subMenuBtn > span not found
warn: currentTest.recordFailure: Element css=li.item-175.first > a.subMenuBtn > span not found
When I read command line logs, Jenkins and commandline are different from firefox launch. On command line I can see a firefox poping, not with jenkins.
Without -debug, jenkins stops at "checking resource aliases".
I launched tomcat for jenkins as admin, still got my problem.
Any ideas?
From the paths being referenced, it looks like your Selenium server is in a Windows environment.
Since Selenium interacts with the desktop, make sure that the user account your Jenkins service is running under has the appropriate permissions to do that. (ie, run it as a named account and give that account access to the desktop via Computer Management / Services).
That would explain why you're seeing different behaviour running from the command line (as your user account) compared to in Jenkins (as the Jenkins service user account).
You can try js-code to fix this error. JS-redirect. As:
storeEval window.location="http://yourWebsiteToOpen.com"; js
echo ${js}
At least It helped for us.

Jenkins & TestNG start browsers

Is it possible to make Jenkins use actual browser instead of headless browser? I a running some tests written in TestNG (using Selenium webdriver). When I run the testng.xml file in Eclipse, the browser starts and the tests run. But when I use Jenkins and run the tests with maven, it doesn't start any browsers.
If your jenkins is hosted in a Windows machine, there are some special configurations you should know about services that are allow to use the interface.
By the way, the easiest way to see the browsers running is starting jenkins using the command line:
java -jar jenkins.war
In linux you could use the same command or use xvfb plugin to run browsers in background.
Hope helps
In addition to this, the main reason for not launching the browser is JNLP (java network launch protocol) , when we execute the war we can interact with the desktop applications.
Using Selenium Grid will allow you to execute the test on Jenkins but open the browser on a remote slave.
To achieve this you need to create an instance RemoteWebdriver than ChromeDriver, IEDriver etc I
For linux. If jenkins is running as a daemon, you could specify active display to connect to and run your browser on it. Check what display you could connect to:
ps e | grep -Po " DISPLAY=[\.0-9A-Za-z:]* " | sort -u
My output is:
DISPLAY=:10.0
DISPLAY=:2
DISPLAY=:2.0
Then go to your jenkins project -> Configure -> Build and add the next string above your main build configuration through "Add build step -> Execute shell"
/bin/bash -c "export DISPLAY=:10"
Edited: I've encountered the issue again recently. To resolve it:
I've given for the jenkins' user ability to interact with the desktop of my current user:
xhost +si:localuser:jenkins
so if I connect to my linux system through ssh using jenkins' user credentials, export display of my current user (export DISPLAY=:10) and run, for example google-chrome or firefox inside of putty's terminal, they are launching on my current user's desktop.
After this I've checked If I could start "mvn test" command inside of workspace/MyTests folder from my putty so it will start browser and execute tests.
At the end I've created simple script in the root of my current user:
vi ~/.startup.sh
#!/bin/bash
xhost +si:localuser:jenkins
and added it to my Xfce4 GUI: Application -> Settings -> Session and Startup -> Application Autostart, specifying command field as:
sh -c $HOME/.startup.sh
It's because of this script should work only when desktop is loaded to share my current user's display with jenkins' user. After reboot and connecting to this server through RDC desktop loads with xhost command applied. And after this jenkins could interract with desktop even when I close the RDP connection but leaving current user's session alive.
I've removed Build step in my jenkins' project configuration that was stated "Invoke top-level Maven targets". It could not start my browsers.
I've changed my "Add build step -> Execute shell" to:
export DISPLAY=:10
cd /var/lib/jenkins/workspace/MyTests
mvn test
I've tried grid also, turning selenium-server-standalone -hub and -node into daemons. But it was slower than launching browsers with WebDriver in the such way.

Web Driver Curl Exception

Trying to use Codeception Web Driver and Selenium to emulate ajax through an acceptance test. I was using PhpBrowser but when I was having issues with Ajax my friend suggested WebDriver.
After enabling it and downloading the selenium (and running it) I get the following error.
[WebDriverCurlException]
Curl error thrown for http POST to http://127.0.0.1:4444/wd/hub/session
with params: {"desiredCapabilities":{"browserName":"googlechrome"}}
Failed to connect to 127.0.0.1 port 4444: Connection Refused
I made sure I was running selenium on port 4444.
java -jar selenium-server.jar -port 4444
acceptance.suite.yml below
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- REST
config:
WebDriver:
url: 'http://life1605.dev'
browser: googlechrome
REST:
url: 'http://life1605.dev'
I had the same problem, with the exact same error message. For some strange reason, it looked like starting the selenium server from command line did not work.
My solution turned out to be manually opening the selenium server through Windows Explorer, right click on the file, choose Open with -> Java Platform SE Binary.
Took me almost 3 hours to figure it out, so I hope this helps somebody.
I had this problem and it turned out a new version of Firefox was incompatible with the addon that Selenium uses to communicate with Firefox.
When you start your tests you should see the new Firefox window appear, and have 30 seconds or so before it goes away again. Within this time, if you type about:addons into the URL field and then click on "Extensions", you should see the "Firefox WebDriver" addon there, and it should be enabled.
For me it was disabled as it was incompatible with the latest Firefox version. So the solution in this case was to either downgrade Firefox or wait for an updated Selenium.
Note that the addon is only installed in the Firefox instance under test, so you won't see it when you use Firefox outside of Selenium.
I had this same problem, I forgot to run phantom.js before trying to do any browser tests. I ran phantomjs and it worked.
I had this problem, and then I remembered that I need to run Xvfb -ac :0 -screen 0 1280x1024x16 & after every Homestead reload (before running Dusk tests).
Then Dusk works instead of saying:
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown
for http POST to /session with params:
{"desiredCapabilities":{"browserName":"chrome","platform":"ANY"}}
Operation timed out after 30000 milliseconds with 0 bytes received
See https://stackoverflow.com/a/42630737/470749