TestingSelenium » History » Version 27
Andreas Kohlbecker, 03/18/2013 10:53 AM
1 | 26 | Andreas Kohlbecker | {{>toc}} |
---|---|---|---|
2 | 1 | Andreas Kohlbecker | |
3 | |||
4 | 26 | Andreas Kohlbecker | ---- |
5 | |||
6 | |||
7 | |||
8 | 1 | Andreas Kohlbecker | ## Functional Website Testing with Selenium |
9 | |||
10 | |||
11 | 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. |
12 | 1 | Andreas Kohlbecker | |
13 | |||
14 | |||
15 | ### Install SeleniumHQ |
||
16 | |||
17 | |||
18 | 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: |
19 | 1 | Andreas Kohlbecker | |
20 | 13 | Andreas Kohlbecker | ~~~ |
21 | 18 | Andreas Kohlbecker | mkdir /usr/lib/selenium |
22 | cd /usr/lib/selenium |
||
23 | 13 | Andreas Kohlbecker | wget http://selenium.googlecode.com/files/selenium-server-standalone-${Version}.jar |
24 | 14 | Andreas Kohlbecker | ln -s selenium-server-standalone-${Version}.jar selenium-server.jar |
25 | ~~~ |
||
26 | |||
27 | Test run the selenium server |
||
28 | |||
29 | ~~~ |
||
30 | 18 | Andreas Kohlbecker | edit-develop:/usr/lib/selenium# java -jar selenium-server.jar |
31 | 14 | Andreas Kohlbecker | 15-Mar-2011 12:29:48 java.util.prefs.FileSystemPreferences$2 run |
32 | INFO: Created user preferences directory. |
||
33 | 12:29:48.291 INFO - Java: Sun Microsystems Inc. 17.1-b03 |
||
34 | 12:29:48.295 INFO - OS: Linux 2.6.26-1-xen-amd64 amd64 |
||
35 | 12:29:48.299 INFO - v2.0 [b2], with Core v2.0 [b2] |
||
36 | 12:29:48.475 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub |
||
37 | 12:29:48.479 INFO - Version Jetty/5.1.x |
||
38 | 12:29:48.479 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver] |
||
39 | 12:29:48.479 INFO - Started HttpContext[/selenium-server,/selenium-server] |
||
40 | 12:29:48.479 INFO - Started HttpContext[/,/] |
||
41 | 12:29:48.507 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@68e6ff0d |
||
42 | 12:29:48.507 INFO - Started HttpContext[/wd,/wd] |
||
43 | 12:29:48.511 INFO - Started SocketListener on 0.0.0.0:4444 |
||
44 | 12:29:48.511 INFO - Started org.openqa.jetty.jetty.Server@30f7f540 |
||
45 | 13 | Andreas Kohlbecker | ~~~ |
46 | 1 | Andreas Kohlbecker | |
47 | 17 | Andreas Kohlbecker | See also [Installing Selenium server 2 as a service](http://www.danstraw.com/installing-selenium-server-2-as-a-service-on-ubuntu/2010/09/23/.) |
48 | 16 | Andreas Kohlbecker | |
49 | 1 | Andreas Kohlbecker | |
50 | ### Install xvfb |
||
51 | |||
52 | |||
53 | 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. |
54 | 1 | Andreas Kohlbecker | |
55 | |||
56 | To install xvfb: |
||
57 | |||
58 | ~~~ |
||
59 | 11 | Andreas Kohlbecker | sudo apt-get install xvfb apt-get libgl1-mesa-dri xfonts-cyrillic xfonts-100dpi xfonts-75dpi |
60 | 1 | Andreas Kohlbecker | ~~~ |
61 | And then to check everything’s OK: |
||
62 | |||
63 | ~~~ |
||
64 | Xvfb :99 |
||
65 | ~~~ |
||
66 | 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. |
67 | 1 | Andreas Kohlbecker | |
68 | 2 | Andreas Kohlbecker | |
69 | |||
70 | ### Install iceweasel (firefox) |
||
71 | |||
72 | 1 | Andreas Kohlbecker | |
73 | 26 | Andreas Kohlbecker | Iceweasel is a fork [[from|Firefox]] with the following purpose. |
74 | 1 | Andreas Kohlbecker | |
75 | 26 | Andreas Kohlbecker | |
76 | Iceweasel can be installed from the Debian repository with |
||
77 | |||
78 | @ apt-get install icewease@. |
||
79 | |||
80 | Nevertheless a **newer backport** from the [Debian Mozilla team](http://mozilla.debian.net/) is usually preferable: |
||
81 | |||
82 | |||
83 | Add the sources (in this example for debian squeeze), add the apt key and install the latest iceweasel release |
||
84 | |||
85 | 1 | Andreas Kohlbecker | ~~~ |
86 | 26 | Andreas Kohlbecker | echo "deb http://backports.debian.org/debian-backports squeeze-backports main" > /etc/apt/sources.list/iceweasel.list |
87 | echo "deb http://mozilla.debian.net/ squeeze-backports iceweasel-release" >> /etc/apt/sources.list/iceweasel.list |
||
88 | apt-get install pkg-mozilla-archive-keyring |
||
89 | apt-get update |
||
90 | apt-get install -t squeeze-backports iceweasel |
||
91 | 1 | Andreas Kohlbecker | ~~~ |
92 | 26 | Andreas Kohlbecker | |
93 | 27 | Andreas Kohlbecker | ==== Test & troubleshooting iceweasle & tests === |
94 | 26 | Andreas Kohlbecker | |
95 | 27 | Andreas Kohlbecker | |
96 | ===== Remotely via X11 forwarding ==== |
||
97 | |||
98 | |||
99 | Open a ssh session with X11 forwarding (with compression) and start icewaesel from within the session |
||
100 | |||
101 | ~~~ |
||
102 | ssh -c arcfour,blowfish-cbc -XC root@160.45.63.201 |
||
103 | iceweasel & |
||
104 | ~~~ |
||
105 | After a little while (depending on the connection speed) iceweasel will appear on your local computer screen. |
||
106 | |||
107 | |||
108 | ===== Headless ==== |
||
109 | |||
110 | 2 | Andreas Kohlbecker | And then, once you’re installed, to test that it works OK. |
111 | |||
112 | 1. Start Xvfb in one window as above, |
||
113 | |||
114 | 1. then in a second terminal window: |
||
115 | |||
116 | ~~~ |
||
117 | export DISPLAY=:99 |
||
118 | firefox |
||
119 | 12 | Andreas Kohlbecker | ~~~ |
120 | 2 | 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. |
121 | |||
122 | The “export DISPLAY=:99″ line is telling firefox to use display # 99, which we started above. |
||
123 | |||
124 | 1 | Andreas Kohlbecker | |
125 | 27 | 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. |
126 | 1 | Andreas Kohlbecker | |
127 | 2 | Andreas Kohlbecker | |
128 | 6 | Andreas Kohlbecker | See also: |
129 | |||
130 | 5 | Andreas Kohlbecker | * http://www.debianroot.de/server/website-screenshots-von-der-linux-consolen-mit-cutycapt-1196.html |
131 | 1 | Andreas Kohlbecker | |
132 | * http://linuxwiki.de/BildschirmFoto |
||
133 | |||
134 | ~~~ |
||
135 | 6 | Andreas Kohlbecker | apt-get install imagemagick x11-utils |
136 | ~~~ |
||
137 | |||
138 | Now take a screenshot of the `root` window: |
||
139 | |||
140 | |||
141 | ~~~ |
||
142 | export DISPLAY=:99 |
||
143 | import -window root example.png |
||
144 | ~~~ |
||
145 | |||
146 | 8 | Andreas Kohlbecker | The screenshot would look like this: |
147 | |||
148 | 7 | Andreas Kohlbecker | |
149 | [!examplepng|50%!] |
||
150 | |||
151 | |||
152 | 6 | Andreas Kohlbecker | If you want to get a list of all windows currently managed by Xvfb : |
153 | |||
154 | ~~~ |
||
155 | xwininfo -root -tree |
||
156 | 2 | Andreas Kohlbecker | ~~~ |
157 | 15 | Andreas Kohlbecker | |
158 | |||
159 | 1 | Andreas Kohlbecker | |
160 | 19 | Andreas Kohlbecker | ### Jenkins CI |
161 | 15 | Andreas Kohlbecker | |
162 | |||
163 | 19 | Andreas Kohlbecker | Install the Seleniumhq Plugin and configure it according to http://wiki.hudson-ci.org/display/HUDSON/Seleniumhq+Plugin |
164 | 1 | Andreas Kohlbecker | |
165 | 19 | Andreas Kohlbecker | However in order to actually run the test suites we need to configure a **Execute shell** build step which will start selenium using the `headlessSelenium.sh` which is found below. |
166 | 1 | Andreas Kohlbecker | |
167 | 19 | Andreas Kohlbecker | |
168 | 23 | Andreas Kohlbecker | The **Execute shell** build step: |
169 | |||
170 | 19 | Andreas Kohlbecker | ~~~ |
171 | 23 | Andreas Kohlbecker | bash -ex /usr/lib/selenium/headlessSelenium.sh $WORKSPACE http://160.45.63.201/dataportal/jenkins/ $WORKSPACE/test/selenium/TestSuite-search.html |
172 | ~~~ |
||
173 | |||
174 | The headlessSelenium.sh script: |
||
175 | |||
176 | ~~~ |
||
177 | 19 | Andreas Kohlbecker | #!/bin/bash |
178 | # |
||
179 | # USAGE: |
||
180 | 22 | Andreas Kohlbecker | # bash -ex /usr/lib/selenium/headlessSelenium.sh $BASEURL $WORKSPACE $TEST_SUITE |
181 | 19 | Andreas Kohlbecker | # |
182 | # |
||
183 | WORKSPACE=$1 |
||
184 | 1 | Andreas Kohlbecker | BASEURL=$2 |
185 | 22 | Andreas Kohlbecker | TEST_SUITE=$3 |
186 | 19 | Andreas Kohlbecker | |
187 | 20 | Andreas Kohlbecker | SELENIUM="java -jar /usr/lib/selenium/selenium-server.jar" |
188 | 23 | Andreas Kohlbecker | FIREFOX_BIN="/usr/lib/iceweasel/firefox-bin" |
189 | 19 | Andreas Kohlbecker | DISPLAY=":99" |
190 | # |
||
191 | # This option creates screen screennum and sets its width, height, and depth to W, H, and D respectively. |
||
192 | # By default, only screen 0 exists and has the dimensions 1280x1024x8. |
||
193 | # |
||
194 | SCREEN="0 1280x1024x16" |
||
195 | |||
196 | #Use virtual X server |
||
197 | 1 | Andreas Kohlbecker | VIRTUAL_X="Xvfb $DISPLAY" |
198 | 19 | Andreas Kohlbecker | |
199 | 22 | Andreas Kohlbecker | #init |
200 | 19 | Andreas Kohlbecker | if [ -z "$(pidof Xvfb)" ]; then |
201 | $VIRTUAL_X & |
||
202 | fi |
||
203 | export DISPLAY |
||
204 | 1 | Andreas Kohlbecker | |
205 | 23 | Andreas Kohlbecker | $SELENIUM -htmlSuite "*firefox $FIREFOX_BIN" ${BASEURL} ${TEST_SUITE} ${WORKSPACE}/selenium-results.html |
206 | 19 | Andreas Kohlbecker | ~~~ |
207 | 24 | Andreas Kohlbecker | |
208 | The following screenshot givens an example of a Jenkins job configuration: |
||
209 | |||
210 | |||
211 | 25 | Andreas Kohlbecker | [!drupal5-cdm_dataportal_Configpng|50%!] |