I've fiddled with my blog template because I decided I wanted more horizontal viewing space, given that it was using less than a third of my 1920 horizontal pixels. If it feels too spread out for you, I added a drag-and-drop handle over to the left to let you resize the main content column. The javascript is pretty primitive. If it breaks, drop me a comment.

Tuesday, October 14, 2008

How To: Run Selenium Tests with Hudson on a Headless Linux Server, Part Two--xwd and xwud

In Part One, I explained how to start Xvfb to give you a virtual display to run graphical applications on. In this post, we'll verify that it's working properly by starting xclock and taking a screenshot of it. Being able to take a screenshot of a virtual display is a pretty useful skill all by itself. To take and view the screenshot, you'll use two different programs: xwd and xwud. The former takes the screenshot; the latter shows it. These should have been installed with your X server (I think).
First, start xclock on the system where Xvfb is running with xclock -display :5.0 so that it will run on the virtual display. Next, also on the system with Xfvb, take the screenshot with
xwd -root -display :5.0 -out xwdout
The breakdown:
Tells xwd to capture the "root" window. This means it captures the entire screen. You can tell it to only capture a certain window if you want. See the -id and -name parameters in the man page if you want to try that.
-display :5.0
Tells xwd to look at screen 0 of display 5. This is why you have to know that info from when you started Xvfb!
-out xwdout
Gives the name of the output file to write the screenshot to. Xwd uses a custom binary format for its files. They can be read by xwud (next), and I understand that they can be converted to other formats by ImageMagick (free!), though I haven't tried it yet.
After taking the screenshot, you'll need to get the output file to a system that has a real X server running, so you can see the image. Some options for this are ftp or sftp, scp, or good old Sneakernet. Finally, view the screenshot you took: xwud -in xwdout. This shows the image stored in the file named xwdout. It should open a window where you can see a happy little xclock showing the time it was whenever you took the screenshot. Click anywhere in the window to close it.
That's it for this post. In Part 3: how to make Hudson, Selenium, and your build play with all this other stuff you've learned.


lh said...

Re: opening screenshot, Gimp successfully opened the screenshot file for me. With xwud, I encountered a "cannot open display" error that didn't respond to trying various settings for -display "..." when launching xwud.

Anonymous said...

This is really good stuff, hoping you will publish the next parts soon! Congrats.

Anonymous said...

Nevermind, just seen the last part, you didn't link it from here. Great work!

Ryan said...

Quite right, Anon. My bad for not making a link to part three. Fixed.