Running Selenium :: WebDriver :: Firefox inside Xvfb from rubies as NON-root user

I am trying to do silent testing using a ruby ​​script. In fact, I run Xvfb on the display: 1, and then run Watir::Browser.new(:firefox) using watir-webdriver.

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

The problem is that I need to be able to call this ruby ​​script from a Rails application and NOT run it as root ... if I try to run the script from the command line as a regular user, Xvfb will fire: 1, as usual, but Watir does not launch the browser ... it eventually expires after 60 seconds. Connection via VNC shows a black screen with the mouse cursor.

I can do all the work from the command line - start Xvfb, then run firefox --display=:1 and the browser will start, so this should be a Selenium problem, right?

In a nutshell: Selenium / Webdriver refuses to launch the browser inside Xvfb unless I run the script as root.

+6
source share
3 answers
  • SOLVED - EDIT * - Sorry, I could not answer this question, but apparently my account is too new to do so for now.

Solved! It's amazing how such things tend to solve themselves AFTER you asked a question ...

For those who want to know why, I had to do something ...

1) Make sure that the corresponding user has a working home directory (www-data was not the default ... his home directory was owned by root)

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

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

4) Try again # 2 - if you had a configuration error earlier, it should disappear.

5) Try running the script again.

This worked like a charm for me, so if you are having problems with Xvfb and watir-webdriver from a web application, give it a try.

Thanks to everyone for contributing to being the best BEST Q&A site on the Internet ... this place saved my ass more than once I would like to mention.

Note: the user initially introduced this change in his question because they could not figure out how to send it as an answer. This was later edited out of the question by some good person, but was never added as an answer.

+3
source

Hi, I don’t know if this will help. It really helped me. I needed to start watir-webdriver automatically at startup / reboot - it worked for me (read also the comments).

+1
source

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

0
source

Source: https://habr.com/ru/post/886638/


All Articles