Configuring Sahi with Xvfb
warning
NOTE: We do not recommend headless execution.
Troubleshooting scripts in a headless environment can be tricky.
warning
If you are looking at headless execution for integration with your CI server,
read our recommended Jenkins/CI setup without headless playback.
What is 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.Installing Xvfb
Ubuntu
runapt-get install Xvfb
For Fedora
runyum 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
root
user.
export DISPLAY=:1 firefox //for firefox
export DISPLAY=:1 chrome //for chrome
startx -- `which Xvfb` :1 -screen 0 1024x768x24&
info
if you get following error:
then run
for
Example:
startx -- `[Xvfb Path]` :1 -screen 0 1024x768x24&
[Xvfb Path]
run
which Xvfb
startx -- `/bin/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>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>
<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>
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