photo
Jordan Sissel
geek

Sat, 08 Apr 2006

Xvfb + Firefox

Resig has a bunch of unit tests he does to make sure jQuery works properly on whatever browser. Manually running and checking unit test results is annoying and time consuming. Let's automate this.

Combine something simple like Firefox and Xvfb (X Virtual Frame Buffer), and you've got a simple way to run Firefox without a visible display.

Let's start Xvfb:

startx -- `which Xvfb` :1 -screen 0 1024x768x24
This starts Xvfb running on :1 with a screen size of 1024x768 and 24bits/pixel color depth. Now, let's run firefox:
DISPLAY=:1 firefox

# Or, if you run csh or tcsh
env DISPLAY=:1 firefox
Seems simple enough. What now? We want to tell firefox to go to google.com, perhaps.
DISPLAY=:1 firefox-remote http://www.google.com/
Now, let's take a screenshot (requires ImageMagick's import command):
DISPLAY=:1 import -window root googledotcom.png
Lets see what that looks like: googledotcom.png

While this isn't complicated, we could VERY EASILY automate lots of magic using something like the Selenium extension, all without requiring the use of a visual display (Monitor). Hopefully I'll find time to work on something cool using this soon.

Problems with screen scraping and other website interaction automation is that it almost always needs to be done without a browser. For instance, all of my screen scraping adventures have been using Perl. Browsers already know how to speak to the web, so why reinvent the wheel?

Firefox has lots of javascript-magic extensions such as greasemonkey and Selenium to let you execute browser-side javascript and activity automatically. Combine these together with Xvfb, and you can automate lots of things behind the scenes.

Tie this back to unit tests. Instead of simply displaying results of unit tests, have the page also report the results to a cgi script on the webserver. This will let you automatically test websites using a web browser and have it automatically report the results back to a server.

Comments: 13 (view comments)
Tags: , , , ,
Permalink: /geekery/xvfb-firefox
posted at: 03:53


13 responses to 'Xvfb + Firefox'

David O'Dell posted at Wed Nov 1 17:14:49 2006...
Got this to work but I'm a little nervous about depending on it to monitor my site.
The selenium extension for firefox makes it real easy to setup and run.

Jordan Sissel posted at Wed Nov 1 17:30:19 2006...
Manual testing is more human-verifyable. Certainly it might be more comforting to watch it run. You should consider, however, that automated testing is better simply because you happens without your guidance.

David O'Dell posted at Thu Nov 9 13:03:21 2006...
Changed my mind on this, I now have this running in nagios. The combination of Xvfb/selenium/firefox/perl/nagios/rrd means I have a way to measure the customer experience including interacting with java script and the java applet that is the main focus of our site.

Alex posted at Tue Dec 12 10:09:31 2006...
Nice... but for some reason doesn't work on my box :(

DISPLAY=:2 firefox
Xlib: connection to ":2.0" refused by server
Xlib: No protocol specified

xdpyinfo:  unable to open display ":2".
No running windows found
Xlib: connection to ":2.0" refused by server
Xlib: No protocol specified


(firefox-bin:13461): Gtk-WARNING **: cannot open display:
firefox-bin exited with non-zero status (1)


And server in it's turn is saying:
AUDIT: Tue Dec 12 10:06:09 2006: 13448 Xvfb: client 1 rejected from local host

Any ideas why that could be happening?

Alex posted at Tue Dec 12 10:19:33 2006...
Nice... but for some reason doesn't work on my box :(

DISPLAY=:2 firefox
Xlib: connection to ":2.0" refused by server
Xlib: No protocol specified

xdpyinfo:  unable to open display ":2".
No running windows found
Xlib: connection to ":2.0" refused by server
Xlib: No protocol specified


(firefox-bin:13461): Gtk-WARNING **: cannot open display:
firefox-bin exited with non-zero status (1)


And server in it's turn is saying:
AUDIT: Tue Dec 12 10:06:09 2006: 13448 Xvfb: client 1 rejected from local host

Any ideas why that could be happening?

Jordan Sissel posted at Thu Jan 11 18:13:17 2007...
Alex,

This is happening because your X server is rejecting connections.

You need to use Xvfb -a or use the startx method (which hopefully sets up xauth properly).

Eric posted at Sun Mar 25 01:01:23 2007...
How can I get mozilla to open to the same dimensions as the Xvfb dimensions?? I am getting a small mozilla window and a 1024x768 desktop background

thx for any pointers

Eric

era posted at Wed Apr 18 07:49:56 2007...
@Eric: Firefox accepts -height and -width although it seems to be broken in Ubuntu.  Maybe it works on other distros, though.

Andy posted at Sat Nov 3 15:05:25 2007...
You should also check out the gtkmozembed bindings available for ruby, python, perl..

Yemek posted at Fri Nov 16 14:37:27 2007...
I using mozilla firefox.

George posted at Mon Jan 21 20:09:46 2008...
hi..

I am trying to automate the selenium test with cruice contol. I want want to run the selenium tests with out xserver. I have written an ant target for that, that doesn't work for me.

<target name="run-selenium-tests" depends='start_server'>
  <echo message="Running selenium test cases"/>
  <mkdir dir="${selenium.test.report.dir}" />
  <exec executable="java">
  <env key="DISPLAY" value=": a"/>
<arg line="-jar ${selenium.lib.dir}/selenium-server.jar"/>
  <arg line="-avoidProxy -htmlSuite &quot;${firefox}&quot;"/>
  <arg line="&quot;${base.url}&quot;"/>
  <arg line="&quot;${selenium.test.list.dir}${test.suite}&quot;"/>
  <arg line="&quot;${selenium.test.report.dir}/result.html&quot;"/>
  </exec>
  </target>

can you please suggest

Thnaks

BK posted at Tue Feb 12 14:28:00 2008...
Hi Folks:


Have u ever got this working on Windows platform with Cywin Xvfb?.

Thanks,
BK

EricL posted at Fri Feb 15 05:37:53 2008...
The real reason I'd take this approach
over something like, say WWW::Mechanize with a wrapper script, would be javascript.

My 'monitoring' requirements are generally 24x7 every few minutes.

It's becoming more frequent that I run into a 'monitor' requirement that involves 'walking' a site to test a specific function which requires AJAX or other javascript activity (some apps use AJAX because they can, not because they need to).

Running firefox w/ selenium in Xvfb on a linux host could help me avoid the *nix to windows integration (due to my lack of expertise).  It also helps to avoid the expense of a full blown tool like loadrunner and/or the monthly expense of using gomeznetwork type products.

Maybe I'd get something running some rainy day.


Leave a reply

You need javascript enabled to use this form. Anti-spam efforts ongoing. Also, if the comment doesn't show up, it's because the form expired. Go back and copy your comment, reload the form, and resubmit. Apologies if this is a hassle, I'm just playing with antispam methods right now. If this insists on not working, please email me about it.

Name (required)
E-mail (optional. Not posted or recorded anywhere, ever)
URL (also optional)
Comment:


Search this site

Navigation

Metadata

Home About Resume My Code

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials

Tag Cloud

Calendar

< April 2006 >
SuMoTuWeThFrSa
       1
2 3 4 5 6 7 8
9101112131415
16171819202122
23242526272829
30      

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati