Running Selenium::WebDriver::Firefox inside Xvfb from ruby as NON-root user
Asked Answered
W

3

6

I'm trying to do some headless testing using a ruby script. Essentially I'm executing Xvfb on display :1, and then firing up Watir::Browser.new(:firefox) using watir-webdriver.

This works great if you run the script as root - I can run x11vnc and watch the script execute the browser and interact with it.

The problem is, I need to be able to call this ruby script from a Rails app, and NOT run it as root... if I try to run the script from the command line as a regular user, Xvfb fires up on :1 as usual, but Watir won't start a browser... it eventually times out after 60 seconds. Connecting via VNC reveals a black screen with mouse cursor.

I can do the whole lot from the command line - start Xvfb, then start firefox --display=:1 and the browser starts up, so it must be a Selenium issue, right?

Nutshell: Selenium/Webdriver refuses to start a browser inside Xvfb unless I run the script as root.

Winton answered 25/4, 2011 at 19:5 Comment(2)
+1 for adding your solution once you got it rightForage
@user724205 Your answer should be added as an answer, not copied into the question.Barbera
S
4
  • SOLVED - EDIT * - sorry I couldn't ANSWER the question, but apparently my account is too new to do that just yet.

Solved! Amazing how things like this tend to solve themselves AFTER you've asked the question...

For those wanting to know why, there's a few things I needed to do...

1) Make sure the user in question has a working home directory (www-data didn't by default... its home dir was owned by root)

2) Start Xvfb from command line, and then start firefox from the command line (NOT from within the script) - this will populate the users home folder with the usual .dbus, .gconf etc folders

3) If you get a massive delay and then an error message along the lines of "an error occurred while loading or saving configuration information for firefox-bin", delete the .dbus folder in the users home directory

4) Try #2 again - if you had a config error before, it should now be gone.

5) Try running the script again.

This worked like a charm for me, so if you're having similar issues running Xvfb and watir-webdriver from within a web app, give it a try.

Thanks to all for contributing to what is hands-down the BEST Q&A site on the web... this place has saved my butt more times than I care to mention.

Note: the user originally entered this amended to their question, because they could not figure out how to post it as an answer. That was later edited out of the question by some well meaning person but never added as an answer.

Sheepshanks answered 1/7, 2014 at 20:5 Comment(0)
R
1

Hi don't know if this link could be a help for you. This helped me a lot. I needed to run watir-webdriver automatically at startup/reboot - it worked for me (read the comments as well).

Rothstein answered 21/6, 2011 at 7:21 Comment(0)
W
0

You should also take a look at Ruby wrapper for Xvfb http://rubygems.org/gems/headless

Witless answered 28/12, 2011 at 6:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.