Error: cannot open display: :0 for Selenium tests - selenium

Firstly I was getting the following error:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: no display specified
So I have used export DISPLAY=:0 to circumvent this problem. Followed to that I have found Selenium tests were running using the root user and all was fine.
However now I can see when these tests are getting executed from Jenkins the following error is coming up:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
No protocol specified
Error: cannot open display: :0
I am running this on a Redhat 6 box.

You can download the Jenkins xvnc plugin and make that plugin start(and export) a virtual display for selenium to use.
The jenkins user may not have access to the :0 display.

The best approach to solve this problem is making changes to the jenkins start script.
The solution that works on Ubuntu for me correctly is as follows:
1.Open Jenkins shell script located at: /etc/init.d/jenkins.
2.Add the following lines as follows before PATH variable:
/usr/bin/X :0 vt7 -ac
export DISPLAY=:0
xhost +

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+Jenkins+Chromedriver = WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally

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.

Using intern js how to configure selenium grid without localhost proxy

I am writing functional test case using intern.js. I wanted to run my test case in selenium grid which is already configured. I changed tunnel: 'NullTunnel' and webdriver: {
host:'',
port: 4444
}
In the intern configuration file and tried to execute my test case. I expect my testcase to be run on grid-config. But the intern is not running the testcase instead throws following error.
FATAL ERROR
Error: [POST http://localhost:4444/wd/hub/session] connect ECONNREFUSED
Error: connect ECONNREFUSED
at errnoException
at Object.afterConnect [as oncomplete]
Note: I did not run 'java -jar selenium-server-standalone-2.xx.x.jar -hub http://hub-server:4444/grid/register' command because I don't want to use my local machine as proxy.
But I want intern-runner to run the testcase directly through selenium grid.
Please help me on how to configure this.
Thanks
I found the solution my self by adding tunnelOptions in the config with host and port information of the grid.
Thanks

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