Project

General

Profile

TestingSelenium » History » Version 15

Andreas Kohlbecker, 03/15/2011 12:46 PM

1 1 Andreas Kohlbecker
2
3
## Functional Website Testing with Selenium
4
5
6 2 Andreas Kohlbecker
We will use [Jenkins CI":http://jenkins-ci.org/ in order to run "SeleniumHQ](http://seleniumhq.org/) tests headlessly on a Debian  server.
7 1 Andreas Kohlbecker
8
9
10
### Install SeleniumHQ
11
12
13 13 Andreas Kohlbecker
The Selenium Server is needed in order to run either Selenium RC style scripts or Remote Selenium Webdriver ones. Download the Selenium Standalone Server from http://code.google.com/p/selenium/ into an appropriate location and create a softlink:
14 1 Andreas Kohlbecker
15 13 Andreas Kohlbecker
~~~
16
mkdir /opt/seleniumhq
17
cd /opt/seleniumhq
18
wget http://selenium.googlecode.com/files/selenium-server-standalone-${Version}.jar
19 14 Andreas Kohlbecker
ln -s selenium-server-standalone-${Version}.jar selenium-server.jar
20
~~~
21
22
Test run the selenium server
23
24
~~~
25
edit-develop:/opt/seleniumhq# java -jar selenium-server.jar
26
15-Mar-2011 12:29:48 java.util.prefs.FileSystemPreferences$2 run
27
INFO: Created user preferences directory.
28
12:29:48.291 INFO - Java: Sun Microsystems Inc. 17.1-b03
29
12:29:48.295 INFO - OS: Linux 2.6.26-1-xen-amd64 amd64
30
12:29:48.299 INFO - v2.0 [b2], with Core v2.0 [b2]
31
12:29:48.475 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
32
12:29:48.479 INFO - Version Jetty/5.1.x
33
12:29:48.479 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
34
12:29:48.479 INFO - Started HttpContext[/selenium-server,/selenium-server]
35
12:29:48.479 INFO - Started HttpContext[/,/]
36
12:29:48.507 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@68e6ff0d
37
12:29:48.507 INFO - Started HttpContext[/wd,/wd]
38
12:29:48.511 INFO - Started SocketListener on 0.0.0.0:4444
39
12:29:48.511 INFO - Started org.openqa.jetty.jetty.Server@30f7f540
40 13 Andreas Kohlbecker
~~~
41 1 Andreas Kohlbecker
42
43
### Install xvfb
44
 
45
46 2 Andreas Kohlbecker
The following installation instructions have been copied from the great guidance on this topic http://www.danstraw.com/running-selenium-tests-on-debian-headlessly-using-iceweasel-and-firefox/2010/11/24/, though we found that we need to install additional packages we decided repeat and extend this guidance here.
47 1 Andreas Kohlbecker
48
49
To install xvfb:
50
51
~~~
52 11 Andreas Kohlbecker
sudo apt-get install xvfb apt-get libgl1-mesa-dri xfonts-cyrillic xfonts-100dpi xfonts-75dpi
53 1 Andreas Kohlbecker
~~~
54
And then to check everything’s OK:
55
56
~~~
57
Xvfb :99
58
~~~
59 12 Andreas Kohlbecker
Where :99 is the display number. We set it to 99 to avoid any conflict with other displays, should they be attached. The command line should just hang without any comments until you press CTRL-C to close.
60 1 Andreas Kohlbecker
61 9 Andreas Kohlbecker
62 2 Andreas Kohlbecker
63
### Install iceweasel (firefox)
64
65
66
To install iceweasel, which is currently the debian version of firefox:
67
68
~~~
69
sudo apt-get install iceweasel
70
~~~
71 1 Andreas Kohlbecker
And then, once you’re installed, to test that it works OK. 
72 2 Andreas Kohlbecker
73
1. Start Xvfb in one window as above, 
74
75
1. then in a second terminal window:
76
77
~~~
78
export DISPLAY=:99
79
firefox
80
~~~
81 12 Andreas Kohlbecker
you should see nothing except maybe a message that the `extension [RANDR" missing on display ](99.0"`) – firefox should just sit there until you CTRL+C.
82 2 Andreas Kohlbecker
83
The “export DISPLAY=:99″ line is telling firefox to use display # 99, which we started above.
84
85
86 6 Andreas Kohlbecker
we want to take take a screenshot in order to check that everything is ok. We will use ImagMagick to take screen shots in addition we also install the x11-utils in order get the `xwininfo` tool.
87 1 Andreas Kohlbecker
88 2 Andreas Kohlbecker
89 6 Andreas Kohlbecker
See also:
90
91 5 Andreas Kohlbecker
* http://www.debianroot.de/server/website-screenshots-von-der-linux-consolen-mit-cutycapt-1196.html
92 1 Andreas Kohlbecker
93
* http://linuxwiki.de/BildschirmFoto
94
95
~~~
96 6 Andreas Kohlbecker
apt-get install imagemagick x11-utils
97
~~~
98
99
Now take a screenshot of the `root` window:
100
101
102
~~~
103
export DISPLAY=:99
104
import -window root example.png
105
~~~
106
107 8 Andreas Kohlbecker
The screenshot would look like this:
108
109 7 Andreas Kohlbecker
110
[!examplepng|50%!]     
111
112
113 6 Andreas Kohlbecker
If you want to get a list of all windows currently managed by Xvfb :
114
115
~~~
116
xwininfo -root -tree
117 2 Andreas Kohlbecker
~~~
118 15 Andreas Kohlbecker
119
120
### Create the headlessSelenium start up script
121
122
123
124
### Jenkins CI
125
126
127
Install the Seleniumhq Plugin.