Automated Web Software Testing With Selenium
Automated Web Software Testing With Selenium
Regina Ranstrom
Department of Computer Science and Engineering
University of Notre Dame, Notre Dame, IN 46556
Abstract:
A common question for software testers and developers is, when do we
automate testing and when is manual testing sufficient? In the following report I will
describe the benefits of automated testing when applied to a web application. I have also
come to a conclusion about what stage in the development process it is best to begin
testing and what tools are particularly helpful. This experience report will mostly
describe the standard environment for testing with Selenium Integrated Development
Environment (IDE). It includes lessons I learned about script writing, using the Selenium
Integrated Development Environment, and building sustainable, efficient tests that will
save time testing in the long run and ensure that the product is tested often. I will
highlight the areas that a tester will most likely need to aid Selenium, as Selenium is not
always able to sufficiently record and playback user interactions with the browser. I will
also discuss what areas of a web application would benefit most from being tested with a
tool like Selenium and how to be sure that Selenium has tested the functionality of the
most crucial aspects of the program.
Introduction:
A high demand is emerging for methodologies and tools for the quality
assurance of web-based systems. [5] There is a great responsibility for developers and
testers to ensure that web software exhibits high reliability and speed. Somewhat
recently, the software community has seen a rise in the usage of AJAX in web software
development to achieve this goal. [9] The advantage of AJAX applications is that they
are typically very responsive. The virtual Emergency Operations Center is an Emergency
Management Training application that requires this level of interactivity. However,
before Selenium IDE, there was no open source testing tool that could handle the amount
of JavaScript present in AJAX applications, and even give the tester the freedom to add
their own features. [3] Since web software is so frequently modified, the main goal for
any test developer is to create sustainable tests. Unlike shrink-wrap software applications,
web-based applications do not have to be sold or distributed when updates are made.
Compatibility and interoperability are also urgent quality features and cause problems
that are more serious than with traditional programs. So, the question is, can these types
of applications be tested most efficiently via automation or simply by manual testing?
Additionally, what is the best approach to creating maintainable test suites?
Background:
The goal of this research was to successfully test the functionality of a web
application called the virtual Emergency Operations Center or vEOC. The vEOC is a
virtual training environment for various emergency response managers and coordinators.
It also serves as a research tool for cognitive scientists to study the decision-making
process under emergency conditions. This focus of the project is to build a
computational discovery infrastructure to examine the decision-making and
organizational complexities that arise from events associated with the management of
disasters, such as recovering from a hurricane. [14] The vEOC is comprised on the client
side of HTML, JavaScript, AJAX, and Reverse AJAX and on the server side of PHP and
MySQL. The application is designed to be very interactive, as it involves the
communication between multiple users. (i.e. Assistant Mayor, Police Department, Fire
Department, etc.) It also requires quick means of giving and receiving updates (reports,
boards, logs, etc.) so that these users may relay information efficiently. Naturally, an
AJAX application was the development approach as these applications typically data is
exchanged asynchronously between server and browser. Therefore, when updates are
made, to individual parts of the application, those changes will be displayed without
requiring a full-page reload. This provides for quick, responsive environment as would be
necessary in any emergency situation.
automate undergoing a lot of churn? When this script fails, how easy will it be for me to
investigate the failure? One thing that will cause test scripts to fail just about faster than
anything else is the product changing. This is why refactoring tests is so important.
Selenium IDE:
When it comes to automated testing tools, it seems that in fact Selenium will
get the job done best for the lowest cost, (time-wise and financially). Previously, the
common statement with regard to testing JavaScript applications was write once, test
everywhere. Selenium makes this task less of a nuisance as it can be used across
multiple platforms. Writing tests with Selenium makes it very simple to perform tests
often and maintain them. It is clear that automated tests of these kind save a lot of time in
the long run. Using browser recording playback and JavaScript conveniences such as
loops, you will find that Selenium, and tools like it, will save plenty of time when it
comes to testing web applications.
Selenium IDE in an integrated development environment which tests code
while integrating browser activity. The main goal of writing these types of tests is to
mimic user actions to determine if the database and web server are behaving as expected
as they carry out the users commands. Verifications are the heart of selenium tests.
These commands are a way of knowing what part of the application is being tested and
what the user expects the browser to present. Writing tests is relatively easy with
selenium. The end product of a selenium test can be converted to any language, however,
by default, selenium scripts are simply a combination of Selenese commands in an
HTML format. However, by downloading or creating a user extension, as I did,
JavaScript commands may also be implemented. User extensions themselves are created
is used often, (whenever there is a drop-down menu) it could also be reused easily by just
changing the numbers correlating to the number of options in the menu (or menus).
Again, this technique saved a huge amount of time because of the extensive number of
options and is easily modifiable.
Because there are so many different scenarios, test engineers must focus their test
activity on the portion of the application that exercises the majority of the system
requirements and find the most practical ways that the user might use the software.
Limitations:
Something that might have made Selenium better would be if it was a bit easier to
avoid test duplication. Ideally, each test case should only have to be written once, and
should be able to be extracted from larger test schemes which it might be a part of. For
example, the tester has to make the same verifications each time they visit the homepage
or navigate through it. If these verifications were their own test case, they could be
written and modified separately and embedded in several different test scenarios.
However, in Selenium IDE, it is often necessary to rewrite these checks for every test,
which imposes the risk of missing some verifications and makes modification much more
tedious. Selenium allows the tester to create different test cases however it is not
evidently possible, using the IDE, to embed certain test cases in others.
As mentioned, the DOM is an integral part of test script development. [12] Every
Ajax web application is constructed around the structure of the DOM to be manipulated
by message handlers. Because of the infinite options, it is often necessary for the tester to
map out the program and determine the most crucial traversals for functionality. The
Document Object Model is the way JavaScript sees its containing HTML page and
browser state, and therefore, is very helpful to the tester who wishes to mimic this
behavior. It serves the tester well as a clear map of the program and its elements. I found
that access to the DOM very convenient for planning and writing test scripts. However,
Selenium does not make this interface available to Selenium users. It is also quite
difficult to identify XPath locators. To solve this problem I ended up having to install two
more add-ons, X-Pather and DOM inspector. [4] [12] Ideally, these features should be
included as a part of the Selenium Add-On.
Conclusion:
When developing web software, the ultimate goal of the tester or developer is to
ensure that the application is tested often and thoroughly. More often than not, creating
automated test scripts is the best way to be sure that this goal is accomplished. In
particular, the developer wants to be sure to create maintainable test scripts that will last
through the many changes that applications undergo. If modifying or refactoring the test
script does become necessary, there are ways to make sure this job is done quickly and
correctly. The main way is to avoid test duplication. By keeping specific tests selfcontained, they can be reused in several places and only one modification would be
necessary for all instances. An Open Source test tool, Selenium IDE has many
advantages, including an easy to use record and playback tool, and the ability to test
JavaScript inside of the browser. However, as test cases can only be run sequentially and
cannot be embedded in one another in the IDE, writing higher level test scripts can
sometimes be difficult. In addition, the log, which reveals whether or not tests have run
successfully, evidently cannot be exported. However, all in all, the user friendly nature
and the ability to customize commands via user extensions make Selenium IDE an ideal
test suite development environment in many ways.
References:
[1] http://seleniumhq.org/docs/03_selenium_ide.html#id4
[2] http://www.infoq.com/articles/testing-ajax-selenium
[3] C. Titus Brown, Grig Gheorghiu, and Jason R. Huggins. An Introduction to Web
Applications with twill and Selenium 2007.
[4] Brian Marick. When Should a Test be Automated? 1998.
[5] Filippo Ricca and Paolo Tonella. Analysis and Testing of Web Applications. 2001.
[6] http://xpath.alephzarro.com/
[7] http://www.hpl.hp.com/techreports/tandem/TR-87.3.pdf
[8] Antawan Holmes and Marc Kellogg. Automating Functional Tests Using Selenium.
2006.
[9] Ali Mesbah and Arie van Deursen. Invariant-Based Automatic Testing of AJAX
User Interfaces. 2009.
[10] Grig Gheorghiu. A Look at Selenium. 2005.
[11] Sebastian Elbaum, Srikanth Karre, and Gregg Rothermel. Improving Web
Application Testing with User Session Data. 2003.
[12] http://www.w3.org/DOM/#what
[13] http://homepages.cwi.nl/~leon/papers/xp2001/xp2001.pdf
[14] Arie van Deursen, Leon Moonen, Alex van den Bergh, Gerard Kok. Refactoring
Test Code. 2001.
[15] Irma Becerra-Fernandez, Michael Prietula, Greg Madey, Domingo Rodriguez.
Project ENSAYO: A Virtual Emergency Operations Center for Disaster Management
Research, Training and Discovery. 2007.
[15] Johnson, T (2010). vEOC Usibility Test. July 1, 2010.
[16] http://webtest.canoo.com/webtest/manual/WebTestHome.html
[17] http://httpunit.sourceforge.net/
Appendix:
Here is a test that checks the delete inject feature, a part of the After Actions tab.
AAdelete
open
/veoc/mainpanel.php
click
waitForPopUp
link=After Actions
aar
selectWindow
name=aar
click
clickAndWait
link=Open Report
//input[@value='Open Report']
click
click
type
clickAndWait
link=Add Item
link=Delete Item
injectid
submit
This tests verifies all elements on the System Manager Main Panel.
Login
open
/veoc/RegularLoginSM.php
type
name
type
password
clickAndWait
//input[@value='Log In']
selectWindow
title=vEOC 2.0
verifyTextPresent
vEOC 2.0 Exercise Developer Console
verifyElementPresent
link=Exercise Development
verifyElementPresent
link=Logout
30000
testuser
password
verifyElementPresent
verifyElementPresent
verifyElementPresent
verifyElementPresent
verifyElementPresent
verifyElementPresent
verifyElementPresent
verifyElementPresent
verifyElementPresent
verifyElementPresent
link=Exercise Evaluation
link=Exercise Control
link=Links
link=References
link=Training Reports
link=Handbook Developer
link=Script Developer
link=Evaluation Metrics
link=FEMA Training Center
link=Miami-Dade Map
verifyElementPresent
link=Miami-Dade Resources
verifyElementPresent
link=Player Reports
This test iterates through all Login instances, represented first by their index in the
roles menu, and then by the individuals menu.
LoginAll
getEval
Roles = new Array(3, 4, 4,
4, 17, 17, 16, 20, 8, 4, 2);
store
0
i
store
1
in2
store
1
in3
while
${i} < Roles.length
storeEval
Roles[${i}]
individuals
while
${in3} < ${individuals}
open
/veoc/RegularLogin2.php
verifyElementPresent
//h3
verifyElementPresent
//tr[2]/th
type
name
testuser
type
password
password
clickAndWait
//input[@value='Log In']
verifyElementPresent
//form/p[1]
verifyElementPresent
//form/p[2]
select
script
label=Hurricane
select
//select[2]
index=${in2}
select
//div/select
index=${in3}
clickAndWait
//input[@value='Enter']
selectWindow
null
storeElementPresent
//div[5]/div/div/div/p
playertaken
gotoIf
${playertaken}
target
waitForPopUp
MainPanel
30000
waitForPopUp
ExercisePanel
30000
waitForElementPresent
link=Logout
selectWindow
title=vEOC 2.0
clickAndWait
label
storeEval
echo
storeEval
endWhile
storeEval
storeEval
storeEval
endWhile
link=Logout
target
"Player:" + ${in3} + " is
taken"
message
storedVars['in3'] = ${in3} +
1;
storedVars['i'] = ${i} + 1;
storedVars['in2'] = ${in2} +
1;
storedVars['in3'] = 1;
message
in3
i
in2
in3