Selenium - simple example giving a try

Selenium

( http://seleniumhq.org/ ) is an web application testing system. Which can be controlled by many programming languages (C#, Java, Perl, PHP, Python, Ruby). Download: http://seleniumhq.org/download/

The simplest way is to use Selenium IDE, which is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests. Selenium IDE includes the entire Selenium Core, allowing you to easily and quickly record and play back tests in the actual environment that they will run.

Automated version is Selenium Remote Control (RC), which is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser.

Recorded tests can be saved as .html files as single test-cases. They can be run from a test suite:


Suite.html
<table >
<tr><td>Overall Tests </td></tr>
<tr><td><a href="./a.html">TEST CASE A</a></td></tr>
</table>

If you need to set proxy, the easiest way to do that in firefox is to create a new profile with desired proxy settings and then tell selenium-server to use this profile. In the following example the profile is saved in ./firefox-profile.


The test suite is run with following command

java -jar selenium-server.jar -multiwindow -htmlSuite "\*chrome" "http://www.host.com" "suite.html" "results.html" -firefoxProfileTemplate "./firefox-profile"

It is important, that the "http://www.host.com" is replaced by the server, against which the testing is performed. This is because of "Same origin policy" for Java script.




Example:

03.html

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head profile="http://selenium-ide.openqa.org/profiles/test-case">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<link rel="selenium.base" href="http://seleniumhq.org/" />

<title>03</title>

</head>

<body>

<table cellpadding="1" cellspacing="1" border="1">

<thead>

<tr><td rowspan="1" colspan="3">03</td></tr>

</thead><tbody>

<tr>

<td>open</td>

<td>/</td>

<td></td>

</tr>

<tr>

<td>clickAndWait</td>

<td>link=Documentation</td>

<td></td>

</tr>

<tr>

<td>assertTitle</td>

<td>Selenium Documentation</td>

<td></td>

</tr>

<tr>

<td>clickAndWait</td>

<td>link=Support</td>

<td></td>

</tr>

<tr>

<td>assertTitle</td>

<td>Support</td>

<td></td>

</tr>

<tr>

<td>clickAndWait</td>

<td>link=Selenium</td>

<td></td>

</tr>

<tr>

<td>assertTitle</td>

<td>Selenium web application testing system</td>

<td></td>

</tr>


</tbody></table>

</body>

</html>


suite.html

<html>

<body>

<table >

<tr><td>Overall Tests </td></tr>

<tr><td><a href="./03.html">TEST CASE A</a></td></tr>

</table>

</body>

</html>




run_suite.sh

#/bin/sh

java -jar selenium-server.jar \\

-htmlSuite "\*chrome" "http://seleniumhq.org/" "./suite.html" "./suite.result" \\

-firefoxProfileTemplate "./firefox-profile" \\




Tutorials:

http://sites.google.com/site/ycselenium/

http://www.jroller.com/selenium/

http://seleniumhq.org/documentation/tutorials/

All the files from this example.

Comments:

Unfortunately, one drawback to this 4 part -htmlSuite parameter is that if any of the tests fail, the results will not be saved...

Posted by Tester on October 14, 2009 at 03:57 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Members of the EMEA Globalization Center are blogging about the products that comprise the Java Enterprise System stack.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today