Project

General

Profile

TestingSelenium » History » Version 16

Andreas Kohlbecker, 03/15/2011 02:17 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 16 Andreas Kohlbecker
See http://www.danstraw.com/installing-selenium-server-2-as-a-service-on-ubuntu/2010/09/23/ for how to start selenium as service.
43
44 1 Andreas Kohlbecker
45
### Install xvfb
46
 
47
48 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.
49 1 Andreas Kohlbecker
50
51
To install xvfb:
52
53
~~~
54 11 Andreas Kohlbecker
sudo apt-get install xvfb apt-get libgl1-mesa-dri xfonts-cyrillic xfonts-100dpi xfonts-75dpi
55 1 Andreas Kohlbecker
~~~
56
And then to check everything’s OK:
57
58
~~~
59
Xvfb :99
60
~~~
61 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.
62 1 Andreas Kohlbecker
63 9 Andreas Kohlbecker
64 2 Andreas Kohlbecker
65
### Install iceweasel (firefox)
66
67
68
To install iceweasel, which is currently the debian version of firefox:
69
70
~~~
71
sudo apt-get install iceweasel
72
~~~
73 1 Andreas Kohlbecker
And then, once you’re installed, to test that it works OK. 
74 2 Andreas Kohlbecker
75
1. Start Xvfb in one window as above, 
76
77
1. then in a second terminal window:
78
79
~~~
80
export DISPLAY=:99
81
firefox
82
~~~
83 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.
84 2 Andreas Kohlbecker
85
The “export DISPLAY=:99″ line is telling firefox to use display # 99, which we started above.
86
87
88 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.
89 1 Andreas Kohlbecker
90 2 Andreas Kohlbecker
91 6 Andreas Kohlbecker
See also:
92
93 5 Andreas Kohlbecker
* http://www.debianroot.de/server/website-screenshots-von-der-linux-consolen-mit-cutycapt-1196.html
94 1 Andreas Kohlbecker
95
* http://linuxwiki.de/BildschirmFoto
96
97
~~~
98 6 Andreas Kohlbecker
apt-get install imagemagick x11-utils
99
~~~
100
101
Now take a screenshot of the `root` window:
102
103
104
~~~
105
export DISPLAY=:99
106
import -window root example.png
107
~~~
108
109 8 Andreas Kohlbecker
The screenshot would look like this:
110
111 7 Andreas Kohlbecker
112
[!examplepng|50%!]     
113
114
115 6 Andreas Kohlbecker
If you want to get a list of all windows currently managed by Xvfb :
116
117
~~~
118
xwininfo -root -tree
119 2 Andreas Kohlbecker
~~~
120 15 Andreas Kohlbecker
121
122
### Create the headlessSelenium start up script
123
124
125
126
### Jenkins CI
127
128
129
Install the Seleniumhq Plugin.