Notes on Web Application Testing - The Risberg Family

jockeyropeInternet και Εφαρμογές Web

2 Φεβ 2013 (πριν από 4 χρόνια και 5 μήνες)

156 εμφανίσεις

Page
1

of
3

Notes on
Web Application Testing

Created 11
/11/08

Updated 02/16/09, Updated 03/20/09, Updated 06/20/09, Updated 10/17/09
, Updated 10/19
/09
, Updated 02/02/10

Updated 03/03/11
, Updated 05/05/11

Introduction

This d
ocument covers web application t
esting.

Thes
e are programs that run a web
-
based application for you
(following a script), and check for specific outputs in ge
nerated screens. They differ

primarily in whether they
connect directly to the server, or automate your browser. The former are better for o
vernight, automated tests, and
while the latter can be used on a nightly basis or interactively. Typically, the script creation is done through hooks
into a browser, in a sense recording a session as the user runs it.


Typical tools are
Selenium

and HTMLU
nit.


See also our document “Notes on Java Unit Testing”.

Selenium

Selenium

is a portable
software testing

framework

for
web applications
.

Selenium provides a record/playback
tool for authoring tests without learning a test scripting language.

Selenium p
rovides a test
domain specific
language

(DSL) to write tests in a number of popular programming languages, including
Java
,
Ruby
,
Groovy
,
Python
,
PHP
, and
Perl
.

Test playback is in most modern
web browsers
.

Selenium deploys on
Windows
,
Linux
,
and
Macintos
h

platforms.


See our document “Notes on Selenium”.


Selenium was developed by a team of programmers and testers at
ThoughtWorks
.

It is
open source software
,
released under the
Apache 2.0 license

and can be downloaded and used without charge.


The curren
t
IDE
version is 1.0.1
0, released Dec
ember 2010, and the
Selenium server version is 2.0b3
.


Selenium tests are known not to be reliable especially while using browsers other than Firefox. Many of the
timeout issues that programmers face while running sele
nium tests are partly due to site delays, network delays
and changes in the site itself rather than that of Selenium. Sometimes, the maintainability of tests itself becomes a
major problem as it takes more time to maintain tests than do manual testing, ho
wever this is an issue with all
automated testing tools. Additionally, due to heavy dependence of Selenium on waits, it becomes major issue
while automating AJAX
-
based sites.

Resources

Go to seleiumhq.org.


There is a Selenium 1 version and a Selenium 2 v
ersion (also called WebDriver).

How it Works

Selenium is software that interacts with a browser that is connected to your web application. It send
s

browser
events, and reads parts of the screen back. It can carry out a test script that checks the screen
contents.

HTMLUnit from Gargoyle Software

This is an enterprise
-
class test runner that mimics the behavior of a web browser to test web
-
based software.
Basically, you define a set of operations to be virtually carried out in the browser, and check the res
ults in the
responses.

Page
2

of
3

Resources

The current version is 2.5, released April 2009.


The download is 9MB, which includes a large number of documentation files, the Java Docs for the main classes,
and the following libraries, which are needed to define the ru
ntime:




HtmlUnit also depends upon JUnit and other libraries.

Defining Tests

You code tests in a way similar to JUnit. However, the tests go into a shell program that uses the supporting
libraries to connect to the application under test. Here is an e
xample:


@Test

public void getElements() throws Exception {


final WebClient webClient = new WebClient();


final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");


final HtmlDivision div = page.getHtmlElementById("some_div_id")
;


final HtmlAnchor anchor = page.getAnchorByName("anchor_name");

}


The basic model is to emulate requests by the client, and then inspect the resulting web page for key identifiers.


Frequently we want to change values in a form and submit the form ba
ck to the server. The following exam
ple
shows how you might do this:



@Test

public void submittingForm() throws Exception {


final WebClient webClient = new WebClient();



// Get the first page


final HtmlPage page1 = webClient.getPage("http://so
me_url");



// Get the form that we are dealing with and within that form,


// find the submit button and the field that we want to change.


final HtmlForm form = page1.getFormByName("myform");



final HtmlSubmitInput button = form.getInputByN
ame("submitbutton");

Page
3

of
3


final HtmlTextInput textField = form.getInputByName("userid");



// Change the value of the text field


textField.setValueAttribute("root");



// Now submit the form by clicking the button and get back the second page.



final HtmlPage page2 = button.click();

}