Sahi Pro - Configuring Sahi with Xvfb

It is sometimes good to run tests headless (without a user interface). It is faster and allows the user to perform other tasks on the computer, while the tests are being run in background. On linux systems, Firefox can be configured to use Xvfb to run Sahi tests in headless mode.

What is xvfb?

From wikipedia (http://en.wikipedia.org/wiki/Xvfb.wikipedia.org/wiki/Xvfb) : Xvfb or X virtual framebuffer is an X11 server that performs all graphical operations in memory, not showing any screen output. From the point of view of the client, it acts exactly like any other server, serving requests and sending events and errors as appropriate. However, no output is shown. This virtual server does not require the computer it is running on to even have a screen or any input device. Only a network layer is necessary.

Installing Xvfb

Ubuntu

run apt-get install Xvfb

For Fedora

run yum install Xvfb

For other linux

Download xvfb.tgz from http://ftp.xfree86.org/pub/XFree86/4.6.0/binaries/FreeBSD-4.x/ Let us consider that the downloaded file is at ~/Downloads.
1) cd /
2) tar xvf ~/Downloads/xvfb.tgz
3) cd /usr
4) sudo mkdir X11R6
5) sudo cp ~/Downloads/xvfb/. /usr/X11R6/
6) chmod +x bin/Xvfb
7) cd bin
8) create a new file Xvfb and add the below script,
#!/bin/sh
mode=$1
case "$mode" in
'start')
if [ -f /usr/X11R6/bin/Xvfb ]; then
echo "<strong></strong><strong>Starting up the Virtual Frame Buffer on Screen 1</strong><strong></strong>"
/usr/X11R6/bin/Xvfb :1 -screen 0 1152x900x8 &
fi
;;
*)
echo " Usage: "
echo " $0 start (start XVFB)"
echo " $0 stop (stop XVFB - not supported)"
exit 1
;;
esac
exit 0
9) chmod +x Xvfb

Setting up Xvfb on display 1


export DISPLAY=:1.0 firefox
startx -- `which Xvfb` :1 -screen 0 1024x768x24

Running test in Xvfb headless browser through Sahi


1) Configure sahi/userdata/config/browser_types.xml to have browser entries as below,
<browserType>
<name>firefox-xvfb</name>
<displayName>Firefox</displayName>
<icon>firefox.png</icon>
<path>env DISPLAY=:1 firefox</path>
<options>-profile "$userDir/browser/ff/profiles/sahi$threadNo" -no-remote</options>
<processName>firefox</processName>
<capacity>5</capacity>
</browserType>
or Click on "Configure" link on Dashboard, and add the above entries before the ending tag in browser_types.xml
2) Save and restart Sahi.
3) To run a test in Xvfb: navigate to sahi/userdata/bin on terminal and run the command
testrunner.sh demo/sahi_demo.sah http://sahi.co.in/demo/ firefox-xvfb