Skip to content
Get Free Trial

Configuring Sahi with Xvfb

From wikipedia (http://en.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.

run apt-get install Xvfb

run yum install Xvfb

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
  1. chmod +x Xvfb
  • login as root user.
  • run following commands.
Terminal window
export DISPLAY=:1 firefox //for firefox
export DISPLAY=:1 chrome //for chrome
startx -- `which Xvfb` :1 -screen 0 1024x768x24&

Running test in Xvfb headless browser through Sahi

Section titled “Running test in Xvfb headless browser through Sahi”
  1. Configure sahi/userdata/config/browser_types.xml to have browser entries as below,- Chrome:

    <browserType>
    <name>chrome-xvfb</name>
    <displayName>Chrome</displayName>
    <icon>chrome.png</icon>
    <path>env DISPLAY=:1 google-chrome --no-sandbox --no-default-browser-check --no-first-run --start-maximized</path>
    <options>--user-data-dir=$userDir/browser/chrome/profiles/sahi$threadNo --proxy-server=127.0.0.1:$port --disable-popup-blocking
    --always-authorize-plugins --allow-outdated-plugins --enable-npapi --incognito</options>
    <processName>chrome</processName>
    <force>true</force>
    <capacity>5</capacity>
    </browserType>
  • Firefox:

    <browserType>
    <name>firefox-xvfb</name>
    <displayName>Firefox</displayName>
    <icon>firefox.png</icon>
    <path>env DISPLAY=:1 firefox -height 768 -width 1024</path>
    <options>-profile "$userDir/browser/ff/profiles/sahi$threadNo" -no-remote</options>
    <processName>firefox</processName>
    <force>true</force>
    <capacity>5</capacity>
    </browserType>

or, on the Dashboard, click Add Browser and add the entries above before the closing 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

Terminal window
./testrunner.sh demo/sahi_demo.sah http://sahi.co.in/demo/ firefox-xvfb