Introduction
Within the software
industry, once a product reaches the stable manual testing phase, every
organization usually thinks of automated testing to save on the costs involved
in manual testing. Since testing cost is an important factor for any project,
organizations have started preferring open source test automation tools (which
have reached a stage where they now rival the commercial ones) instead of
investing in costly commercial testing tools. With no licensing costs, open
source automation testing tools provide competitive features for automating the
testing of software applications as well as Web portals.
A variety of open source
automation testing tools is available for almost all types of testing such as
functional, Web, UAT, regression, performance etc. Because of the extent to
which these open source tools have matured, it’s time to think about them and
have them in your QA automation kit. There are also various open source tools
available to support the different testing types such as White Box Testing
(Unit Testing, for e.g., using JUnit) and Black Box Testing (system/regression
testing, for e.g., using Selenium, Sahi, Watir, TestMaker, LogiTest, TestGen4J,
FitNesse etc).
The scope of this blog is
to cover the basic flow for one of these open source Web testing automation
tools – Selenium.
Why Selenium?
Selenium is probably the
best option for automated testing of Websites today. It is becoming
increasingly popular and it is the first choice of automation testers as well
as organizations for automating the testing of Web-based applications for both
the GUI as well as the functionality. Selenium can also be used as aunit testing tool for JavaScript. We at Xoriant have
been working on Selenium for automating the testing of Web sites developed
using AJAX for the pharmaceuticals and travel industries. The following graph
shows the popularity of Selenium along with other open source automation
testing tools.
Selenium Test PackageSelenium
is a package of various test components which consists of the following three
major tools. Each one has a specific role in aiding the development of test
automation for a Web application.
1. Selenium IDE – A Firefox extension to record test cases and suites.
2. Selenium RC – Used to run tests on different browsers and systems.
4. Qualitia
and Tellurium – A wrapper for the Selenium engine.
Selenium Modes:
Bases on the components
Selenium has following three modes for executing the test cases and test
suites:
§ Record-Playback mode (Selenium IDE):
In this mode only
Selenium IDE is used to record the test scenarios in terms of test cases in
firefox. This is a great way to get started to writing tests and group them together
to form the test suite. The recorded tests can be exported to many programming
languages so that we can tweak them and put them in the testing framework. The
test cases and test suites can be replayed back to check the verifications and
validations or sent to Selenium RC or Grid for further tweaking.
§ Selenium Remote Control (RC) Mode
In this mode Selenium
starts multiple browsers (one at a time) and then runs the recorded test-cases
which are saved in your language of choice. This helps to enhance the test
cases with looping and programming techniques to cover all the required test
scenarios and checks.
§ Test Runner Mode
In this mode the test
cases are recorded ad replayed in the form of HTML tables. This is just one
more facility to execute the Selenium IDE as well as RC test cases. This helps
to check the test results reports in better manner if not formatted already.
Testing AJAX with
Selenium
Selenium
IDE – Recording and updating a script
Selenium IDE is the
FireFox Add-on provided by the Selenium group. This is very simple and easy to
use add-on so that non-programmers can record and create the test scripts for
automating web components. These automated test scripts are used as Selenium RC
test cases by choosing the language code. i.e. Selenium IDE makes easier to
create Selenium RC test cases. (Install Selenium IDE and Selenium RC .
Selenium IDE is used for:
§ Recording
and updating the test cases or write them manually in table tab.
§ Creating
Test Suite by grouping the test cases under one group
§ Exporting
Test Cases/Suites the supported language and save for Selenium RC to enhance
them
§ Finding
reference of every API and Selense commands
§ Debugging
test cases by toggling breakpoints through the commands
How commands generated in
IDE for AJAX pages:
1. Almost
all of the web pages are developed with AJAX technology since web2.0 evolution.
While recording the page elements, Selenium IDE locates the page
elements/objects using xpath/DOM/CSS. XPaths are found
automatically, but you may have to update the specific elements in Xpath
manually by looking into the source of the page to make them unique. Firebug is the helpful firefox Add-on for this purpose.
2. Every
command has maximum two arguments. The first is usually target element pointed
by its ID, name, link, DOM, CSS or XPath and the second is the value to that
target element if exists. The selenium IDE commands when saved in the
programming language of our choice for selenium RC purpose are called as Selenese.
3. The
common commands are open, click, type, assert, verify. Commands beginning with
‘assert’ or ‘verify’ are for checks and verifications. If verify command is
used and it fails, it fails the test case and continue to run the remaining
tests. If assert command is used and it fails, the test case is aborted and
stops to run the remaining tests.
4. For
synchronizing the flow of test execution Selenium has commands ending with
‘AndWait’, it tells Selenium to wait for
the page to load after the action has been done. However, it fails when using
AJAX calls. In this case you have to use ‘WaitFor’ commands.
Selenium IDE – Most
commonly used commands
The following are the
most commonly used commands in the Selenium IDE:
open: Opens
a page using a URL.
click: Clicks
the element/object on the page.
clickAndWait:
Performs a click operation, and optionally waits for a new page to load.
verifyTitle:
Verifies the expected title and continues to run if it fails.
assertTitle:
Verifies an expected page title and stops the execution if it fails.
verifyTextPresent:
Verifies that the expected text is present somewhere on the page.
verifyElementPresent:
Verifies an expected UI element, as defined by its HTML tag.
verifyText:
Verifies that the expected text and its
corresponding HTML tag are present on the page.
waitForPageToLoad:
Pauses execution until an expected new page loads.
WaitForElementPresent: Pauses execution until an expected UI element, as defined by its
HTML tag, is present on the page. Used with AJAX calls.
Get more details about
Selenium IDE here: selenium IDE documantation
No comments:
Post a Comment