Selenium Web Driver does not work on xvfb - firefox

I want to run my Robot Framework tests which include Selenium2Library keywords on an Ubuntu remote machine so they should be run without a display. At first I just tried to run a simple test and get following result:
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
I installed xvfb in order the run headless tests and run these lines on remote shell:
sudo Xvfb :10 -ac
export DISPLAY=:10
Now i am getting the following error and I can't get rid of it
test | FAIL |
WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.
I checked nearly all questions here about Selenium on xvfb and this specific error.
Since some mentioned about Selenium - Firefox incompability, I tried updating selenium (it is up to date, version 2.46.0), my Firefox was latest and i has not worked.
Then I tried using an old firefox relase (35.0) which is also not worked
Now I'm trying a solution for this problem and I am almost sure it is about fireofx.
Thanks for your answers and advices
EDIT:
->Runing tests with chrome works just fine
->Also i checked my iptables if there is a rule blocking network to local, it is in default state

Related

Nightwatch starts selenium and then hangs indefinitely

I'm running a simple nightwatch test on a Windows 10.1 machine. The tests starts up selenium server (e.g., selenium server... started - PID: 12784), but it never gets to the test code. I can use a browser to get to the localhost server page that is spawned from the "node nightwatch.js -t test.js" command, so I know the server is working properly. I've also tried running nightwatch with different browsers, e.g., -e chrome, firefox, IE, and phantomjs, and none of them work. Putting --verbose on the command doesn't provide any more console spew, so not sure how to debug this. I'm running with selenium-server-standalone v2.53.0.
Any suggestions?
Solved my own problem. Turns out the problem was with incompatible versions of node, nightwatch, and python. I figured it out by creating a totally separate clone of my repository and reinstalling all the node/nightwatch/selenium dependencies. Would be nice if there was a debug feature that could be enabled to indicate more details about where a node or nightwatch application is during application startup. I learned of node-inspector, so I'll check it out as a possible debug tool.

selenium UI automation through Teamcity build agent

We are running selenium UI automation through Teamcity build Agent but it couldnt launch firefox and the error is below:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host localhost.localdomain on port 7055 after 45000 ms. Firefox console output:
Error: cannot open display: :0.0
Error: cannot open display: :0.0
Before trying with Teamcity build agent , we have executed the selenium cases manually (by running the ant script) in the build agent VM and it could launch firefox and executed the cases successfully.
so, we don't see any problem of compatibilty between firefox and selenium jar version.
It seems like your configuration misses a virtual display.
You need a virtual display if you want to run selenium with a browser such as Firefox, IE, ..., without any display. You could use Xvfb for that, or headless browser such as phantomJS.
There are a lot of articles about that, like this one
Or you could export your display to a monitoring environment, if you want selenium tests to be displayed while they run.

Headless testing display error

Background
I am running a set of selenium tests using a Maven and Jenkins with Testng. I had them working fine headlessly up until a week ago. Jenkins sits on the server accessible with port 8080. The tests also run fine through eclipse.
Software Versions
I have read lots about Firefox being incomparable with selenium so here is a list of software and versions that I am using.
Firefox: 39
Maven: 3.3.3
Java: 1.7.0_79
Selenium: 2.46 & 2.47(currently 2.47)
Jenkins: 1.622
Xvnc: 1.3.9
ubuntu 14
Error
After I run the tests and the fail I check the console through Jenkins. The error I am getting makes me think it's a problem with Xvnc and firefox but I can't pin point it. I get a NotConnectedException. The firefox console error has changed a few times here is a list of different errors the console has shown me.
Error: cannot open display: :87
firefox: Fatal IO error 11 (Resource temporarily unavailable) on X server :46.
firefox: Fatal IO error 2 (No such file or directory) on X server :78.
Research
I've been on bugzilla but cant find a conclusive answer to the problem.
I've also looked around SO but found no fixes.
Conclution
From what I have gathered it is something to do with Xvnc, Could running
sudo apt-get update
make changes to how Xvnc operates? I have updated the packages some time last week but our testers didn't check Jenkins properly when adding new tests and as such I've wasted and entire day trying to pin point when and what the problem is.
Question
What would cause Jenkins to return errors like this, how can I fix them and how can I prevent something doing this again?
EDIT 1
The display variable seems to be the issue, upon typing the command
echo $DISPLAY
There is no response just an empty line.
EDIT 2
running the command
export DISPLAY=:0.10
no gives the result
:0.10
when I echo $DISPLAY
I think the DISPLAY varibale is not functioning as expected and hence firefox is unable to connect to it. To know more about the $DISPLAY refer this link https://askubuntu.com/questions/432255/what-is-display-environment-variable
Try to run this command on the slave node where the job runs, this should give you the required setting for the tests to connect and run.
nohup /usr/bin/Xvfb :2 –screen 0 1024x768x24 > /dev/null 2>&1 &

Selenium RC test (PHPUnit)

Using, Centos, Apache, PHPUnit, Selenium RC,
I was trying to test selenium RC which is running in one of my server.
java -jar selenium-server-standalone-2.4.0.jar
Initially i got error of firefox creating profile and it doesnot load anything up and gives error.
Secondly i tried to do with given profile location.
java -jar selenium-server-standalone-2.4.0.jar -firefoxProfileTemplate
"/root/.mozilla/firefox/" &
still it shows error
ERROR - Failed to start new browser session, shutdown browser and
clear all session data
INFO - Got result: Failed to start new browser session: Error while launching browser on session null
Please share your view what may be the problem,
Running Mock , it is working, for test purpose, but firefox, is unable to lunch browser session.
Note: its not GUI mode (NO X), it has firefox version 3.6.18,
09:48:20.312 INFO - Got result: Failed to start new browser session: Error while launching browser on session null
09:48:39.659 INFO - Command request: getNewBrowserSession[*firefox3, http://google.co.uk] on session null
09:48:39.659 INFO - creating new remote session
09:48:39.660 INFO - Allocated session 17b9149077f648d3bc89b3f106466c6c for http://google.co.uk, launching...
09:48:39.860 INFO - Preparing Firefox profile...
09:49:00.017 ERROR - Failed to start new browser session, shutdown browser and clear all session data
java.lang.RuntimeException: Timed out waiting for profile to be created!
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.waitForFullProfileToBeCreated(FirefoxChromeLauncher.java:360)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.populateCustomProfileDirectory(FirefoxChromeLauncher.java:114)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.launch(FirefoxChromeLauncher.java:83)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.launchRemoteSession(FirefoxChromeLauncher.java:412)
at org.openqa.selenium.server.BrowserSessionFactory.createNewRemoteSession(BrowserSessionFactory.java:375)
at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:125)
at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:87)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.getNewBrowserSession(SeleniumDriverResourceHandler.java:785)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.doCommand(SeleniumDriverResourceHandler.java:422)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handleCommandRequest(SeleniumDriverResourceHandler.java:393)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle(SeleniumDriverResourceHandler.java:146)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
09:49:00.048 INFO - Got result: Failed to start new browser session: Error while launching browser on session null
After, a whole day research, i got the solution, which may be useful for all of you if this is the case..
If Any issue: Due to the Display issue you may face several problem, such as firefox profile, and firefox lunching, and not being able to load.
Firefox Profile Issue: Copy and paste from another machine if you dont have in given machine.
Firefox Lunching Issue: With No session on null: yum install xorg-x11-Xvfb && Xvfb :99 -ac && export DISPLAY=:99 && firefox
Here if you see any issue regarding xvfb :99 you may have to delete the lock file.
Server is already active for display 99
If this server is no longer running, remove /tmp/.X99-lock
and start again.
Firefox should launch without error, and stay running (until you kill it with Control-C)
It kept giving me the same error(ERROR - Failed to start new browser session, shutdown browser and clear all session data) regardless of what i did. I am running Selenium on a linux box with firefox installed and i am trying to run it headless.
Here is how i resolved the issue:
1.Install xvfb(a virtual display manager) and its dependencies
sudo apt-get install xvfb
sudo apt-get apt-get install libgl1-mesa-dri xfonts-cyrillic xfonts-100dpi xfonts-75dpi
2.Run xvfb like this
sudo Xvfb :99 -ac
This should get it running on display :99. You will see some output
3.Open a new terminal and type this.
export DISPLAY=:99
java -jar selenium-server-standalone-2.37.0.jar
This will set the display to :99. So anything opened from that terminal window that needs to use display will open on the virtual display(which is invisible) managed by xvfb. The second line starts the selenium server, and since selenium will attempt to start firefox, it will start it on this invisible display.
Then run your test. This should get the test setup and the browser will be invisible.

Has anybody run Xvfb on EC2 with CentOS?

I am trying to get javascript-enabled cucumber running on CentOS in EC2 by following this tutorial: http://makandra.com/notes/1391-how-to-hide-your-selenium-browser-window-with-headless However, the scenarios that require javascript just fail without any exception message.
In order to debug, I just went to see if Xvfb is working correctly with according to this tutorial: http://blog.kabisa.nl/2010/05/24/headless-cucumbers-and-capybaras-with-selenium-and-hudson/
I tested the command:
Xvfb :99 -ac -screen 0 1024x768x16
I got the error msg like this:
_XSERVTransSocketOpenCOTSServer: Unable to open socket for inet6
_XSERVTransOpen: transport open failed for inet6/ip-10-116-82-44:99
_XSERVTransMakeAllCOTSServerListeners: failed to open listener for inet6
I googled for solutions about of these errors. I haven't found a good solution for this yet. If I run the same command again, I get:
Fatal server error:
Server is already active for display 99
If this server is no longer running, remove /tmp/.X99-lock
and start again.
So the server is supposed to be up and running already. However, when I tried to run this in followups:
DISPLAY=:99.0 firefox http://www.google.com
The console just hangs there, until I contol + C to kill it.
Is there anyone who knows what's going on here?
Thanks in advance.
It seems that it's okay. Your console didn't hang - it is firefox is working - you just don't see it:)
Edit: I think you can connect there with ssh -X and you'll see firefox window if it is working. (Only if you're running linux/mac on your dev machine)

Resources