6.functional Test Automation PDF
6.functional Test Automation PDF
Laboratory 3
Table of Contents
1. What is Functional Test Automation?
1.1. Overview
1.2. Why using Test Automation
1.3. When to use Test Automation
1.3.1. When to Automate
1.3.2. When NOT to Automate
1.4. Return on Investment
2. Automation Tools
2.1. Tools for Code-driven Testing
2.2. Tools for GUI-Testing
3. Automation Frameworks
3.1. Framework Approach in Test Automation
3.1.1. Why Implement a Framework?
3.2. Types of Automation Frameworks
3.3. General Framework architecture
3.3.1. Master Test Scripts
3.3.2. Common Functions/Tasks (Script Functions)
3.3.3. Data-pools (BD Layer)
3.3.4. Application Map (Object Repository)
3.3.5. Logging Module
4. Selenium-IDE
4.1. Introduction
4.2. Installing the IDE
4.3. Opening the IDE
4.4. IDE Features
4.4.1. Menu Bar
Toolbar
Laboratory 3 – Functional Test Automation
Academy of Economic Studies Cybernetics and Economic Informatics Faculty
Test Case Pane
Log/Reference/UI-Element/Rollup Pane
4.4.2. Log
4.4.3. Reference
4.5. Building Test Cases
4.5.1. Recording
4.5.2. Adding Verifications and Asserts With the Context Menu
4.6. Editing
4.6.1. Insert Command
4.6.2. Insert Comment
4.6.3. Edit a Command or Comment
4.7. Opening and Saving a Test Case
4.8. Running Test Cases
4.9. Commonly Used Selenium Commands
Verifying Page Elements
4.10. Assertion or Verification?
verifyTextPresent
verifyElementPresent
verifyText
4.11. Locating Elements
4.11.1. Locating by Identifier
4.11.2. Locating by Id
4.11.3. Locating by Name
4.11.4. Locating by XPath
4.11.5. Locating Hyperlinks by Link Text
4.11.6. Locating by CSS
4.12. Store Commands and Selenium Variables
storeElementPresent
storeText
storeEval
4.13. Using while loops in Selenium
4.14. Refferences
Laboratory 3 – Functional Test Automation
Academy of Economic Studies Cybernetics and Economic Informatics Faculty
Theoretical Part
● Manual Testing of all work flows, all fields , all negative scenarios is time and cost
consuming
● It is difficult to test for multi lingual sites manually
● Automation does not require Human intervention. You can run automated test unattended
(overnight)
● Automation increases speed of test execution
● Automation helps increase Test Coverage
● Manual Testing can become boring and hence error prone.
So, automated delivered software present the following key benefits:
➢ Cumulative Coverage
It is a fact that applications change and gain
complexity over their useful life. As depicted in the
figure, the feature set of an application grows
steadily over time. Therefore, the number of tests
that are needed for adequate coverage is also
constantly increasing. Just a 10% code change still
requires that 100% of the features be tested. That
is why manual testing can’t keep up – unless you
constantly increase test resources and cycle time,
your test coverage will constantly decline.
Automation can help this by allowing you to
accumulate your test cases over the life of the
application so that both existing and new features can always be tested.
➢ Faster time to market
Automation can help reduce time to market by allowing test execution to happen 24X7. Once the test
library is automated, execution is faster and run longer than manual testing. Of course, this benefit is only
available once your tests are automated.
➢ Reduce cost of failure
Software is used for high risk, mission critical applications that represent revenue and productivity. A
single failure could cost more than the entire testing budget for the next century! In one case a single bug
Laboratory 3 – Functional Test Automation
Academy of Economic Studies Cybernetics and Economic Informatics Faculty
resulted in costs of almost $2 billion. Automation can reduce the cost of failure by allowing increased coverage
so that errors are uncovered before they have a chance to do real damage in production.
Cost of automation = price of hardware + price of software + time to develop scripts + (time to maintain scripts x
number of times scripts are executed) + (time to execute scripts x number of times scripts are executed)
Cost of automation = 2 computers @ $1,000 ea + 2 licenses @ $2,000 ea + 10 days @ $50 hr +
(1 day @ $50 hr x 52 weeks) + (1 hr @ $50 x 52 weeks)
Cost of automation = $2,000 + $4,000 + $4,000 + $20,800 + $2,600
Cost of automation = $33,400
Cost of manual = time to develop test cases + (time to maintain test cases x number of times tests are
executed) + (time to execute manual testing x number of times tests are executed)
Cost of manual = 4 days @ $50 hr + (1 day @ $50 x 26 weeks) + (1 day @ $100 x 52 weeks)
Cost of manual = $1,600 + $10,400 + $41,600
Cost of manual = $53,600
2. Automation Tools
2.1. Tools for Code-driven Testing
A growing trend in software development is the use of testing frameworks such as the xUnit
frameworks (for example, JUnit and NUnit) that allow the execution of unit tests to determine whether
various sections of the code are acting as expected under various circumstances. Test cases describe tests that
need to be run on the program to verify that the program runs as expected.
● JUnit is a unit testing framework for the Java programming language. JUnit has been important
in the development of test-driven development, and is one of a family of unit testing
frameworks collectively known as xUnit that originated with SUnit. JUnit is linked as a JAR at
compile-time; the framework resides under packages junit.framework for JUnit 3.8 and earlier
and under org.junit for JUnit 4 and later.
● NUnit is a unit-testing framework for all .Net languages. Initially ported from JUnit. It is written
entirely in C# and has been completely redesigned to take advantage of many .NET language
features, for example custom attributes and other reflection related capabilities. NUnit brings
xUnit to all .NET languages.
3. Automation Frameworks
3.1. Framework Approach in Test Automation
A simplified scheme of the Test Automation Process will look like in the picture below. In the Design &
Develop phase, it is strongly recommended to implement a Test Automation Framework, or to design a
customized one that would fit best for the tasks it is intended to perform.
A Test Automation Framework is a set of assumptions, concepts or practices that provide support for
automated software testing. It includes test objects, library files, reusable scripts, or anything which helps in
capturing and controlling the test activity. Developing an automated solution is very similar to developing
software. In software development, it is always good to start the development activity with a design in place
★ This kind of framework if most suitable for applications that have low variety in terms of use
case flows. Where there is a core of common actions/flows of actions, from which the test
cases are derived.
● Test Library Architecture Framework
➢ Very similar to the script modularity framework
➢ Divides the AUT into procedures and functions instead of scripts
➢ Library files represent modules, section, and function of AUT
➢ The library files are called directly from the master test case script
★ This kind of framework if most suitable for the same type of applications as for the modular
one.
● Keyword-Driven Testing Framework
➢ Requires the development of data tables and keywords
➢ Tests looks very similar to manual test cases
➢ The data table and keywords are independent of the automation tool
★ This kind of framework if most suitable for application against whom there are not a lot of
actions to be performed. It can be easily used to automate against web-applications, as most
actions can be performed on any type of web-page.\
● Data-Driven Testing Framework
➢ Inputs and outputs are read from data files
o Database, excel files, xml files etc.
➢ Data is loaded into variables in captured or manually coded scripts
➢ It can be implemented using data-pools in the Rational Functional Tester
★ This kind of framework if most suitable for applications that have reached a stability in terms of
functional flows. It is very effective for improving test coverage, negative testing, or boundary
testing. Banking applications would fit to this.
● Hybrid Automation Framework
➢ It is a combination of all above techniques
➢ Allows data driven scripts to take advantage of the powerful libraries and utilities that usually
accompany a keyword driven architecture
➢ Combining the above types of framework, it may result in a structure that allows a large coverage,
using a wide variety and complex actions.
★ This is an ideal type of framework that would ensure coverage, easy maintenance for
changing flows as well as a friendly layout so that non-technical users would be able to read
de code lines.
3.3. General Framework architecture
3.3.1. Master Test Scripts
The test Script is where all the framework components combine. At this level code lines represent
specific actions performed on the Application Under Test. By running a scripts a entire test case flow should
be performed on the application and at the end of the run, results of the actions and verifications performed
should be delivered.
4. Selenium-IDE
4.1. Introduction
The Selenium-IDE (Integrated Development Environment) is the tool you use to develop your Selenium
test cases. It’s an easy-to-use Firefox plug-in and is generally the most efficient way to develop test cases.
It also contains a context menu that allows you to first select a UI element from the browser’s currently
displayed page and then select from a list of Selenium commands with parameters pre-defined according
to the context of the selected UI element. This is not only a time-saver, but also an excellent way of
learning Selenium script syntax.
Laboratory 3 – Functional Test Automation
Academy of Economic Studies Cybernetics and Economic Informatics Faculty
4.2. Installing the IDE
Using Firefox, first, download the IDE from the SeleniumHQ downloads page
Firefox will protect you from installing addons from unfamiliar locations, so you will need to
click ‘Allow’ to proceed with the installation, as shown in the following screenshot.
When downloading from Firefox, you’ll be presented with the following window.
Select Install Now. The Firefox Add-ons window pops up, first showing a progress bar, and
when the download is complete, displays the following.
Restart Firefox. After Firefox reboots you will find the Selenium-IDE listed under the Firefox Tools
menu.
Toolbar
The toolbar contains buttons for controlling the execution of your test cases, including a step
feature for debugging your test cases. The right-most button, the one with the red-dot, is the
record button.
Run All: Runs the entire test suite when a test suite with multiple test cases is loaded.
Run: Runs the currently selected test. When only a single test is loaded this button and the
Run All button have the same effect.
Step: Allows you to “step” through a test case by running it one command at a time. Use for
debugging test cases.
TestRunner Mode: Allows you to run the test case in a browser loaded with the Selenium-Core
TestRunner. The TestRunner is not commonly used now and is likely to be deprecated. This
button is for evaluating test cases for backwards compatibility with the TestRunner. Most
users will probably not need this button.
The other tab - Source displays the test case in the native format in which the file will be
stored. By default, this is HTML although it can be changed to a programming language such
as Java or C#, or a scripting language like Python. See the Options menu for details. The
Source view also allows one to edit the test case in its raw form, including copy, cut and paste
operations.
The Command, Target, and Value entry fields display the currently selected command along
with its parameters. These are entry fields where you can modify the currently selected
command. The first parameter specified for a command in the Reference tab of the bottom
pane always goes in the Target field. If a second parameter is specified by the Reference tab,
it always goes in the Value field.
If you start typing in the Command field, a drop-down list will be populated based on the first
characters you type; you can then select your desired command from the drop-down.
Log/Reference/UI-Element/Rollup Pane
The bottom pane is used for four different functions–Log, Reference, UI-Element, and Rollup–
depending on which tab is selected.
4.4.2. Log
When you run your test case, error messages and information messages showing the progress
are displayed in this pane automatically, even if you do not first select the Log tab. These
messages are often useful for test case debugging. Notice the Clear button for clearing the
Laboratory 3 – Functional Test Automation
Academy of Economic Studies Cybernetics and Economic Informatics Faculty
Log. Also notice the Info button is a drop-down allowing selection of different levels of
information to log.
4.4.3. Reference
The Reference tab is the default selection whenever you are entering or
modifyingSelenese commands and parameters in Table mode. In Table mode, the Reference
pane will display documentation on the current command. When entering or modifying
commands, whether from Table or Source mode, it is critically important to ensure that the
parameters specified in the Target and Value fields match those specified in the parameter list
in the Reference pane. The number of parameters provided must match the number specified,
the order of parameters provided must match the order specified, and the type of parameters
provided must match the type specified. If there is a mismatch in any of these three areas,
the command will not run correctly.
While the Reference tab is invaluable as a quick reference, it is still often necessary to consult
the Selenium Reference document.
4.6. Editing
4.6.1. Insert Command
Table View
Select the point in your test case where you want to insert the command. To do this, in the
Test Case Pane, left-click on the line where you want to insert a new command. Right-click
and select Insert Command; the IDE will add a blank line just ahead of the line you selected.
Now use the command editing text fields to enter your new command and its parameters.
Source View
Select the point in your test case where you want to insert the command. To do this, in the
Test Case Pane, left-click between the commands where you want to insert a new command,
and enter the HTML tags needed to create a 3-column row containing the Command, first
parameter (if one is required by the Command), and second parameter (again, if one is
required to locate an element) and third parameter(again, if one is required to have a value).
Example:
<tr>
<td>Command</td>
<td>target (locator)</td>
<td>Value</td>
</tr>
Table View
Select the line in your test case where you want to insert the comment. Right-click and select
Insert Comment. Now use the Command field to enter the comment. Your comment will
appear in purple text.
Source View
Select the point in your test case where you want to insert the comment. Add an HTML-style
comment, i.e., <!-- your comment here -->.
Table View
Simply select the line to be changed and edit it using the Command, Target, and Value fields.
Laboratory 3 – Functional Test Automation
Academy of Economic Studies Cybernetics and Economic Informatics Faculty
Source View
Since Source view provides the equivalent of a WYSIWYG (What You See is What You Get)
editor, simply modify which line you wish–command, parameter, or comment.
click/clickAndWait
performs a click operation, and optionally waits for a new page to load.
verifyTitle/assertTitle
verifies an expected page title.
verifyTextPresent
verifies expected text is somewhere on the page.
verifyElementPresent
verifies an expected UI element, as defined by its HTML tag, is present on the page.
verifyText
verifies expected text and its corresponding HTML tag are present on the page.
verifyTable
verifies a table’s expected contents.
waitForPageToLoad
pauses execution until an expected new page loads. Called automatically when clickAndWait is
used.
waitForElementPresent
pauses execution until an expected UI element, as defined by its HTML tag, is present on the
page.
verifyTextPresent
The command verifyTextPresent is used to verify specific text exists somewhere on the page.
It takes a single argument–the text pattern to be verified. For example:
Command Target Value
verifyTextPresent Marketing Analysis
This would cause Selenium to search for, and verify, that the text string “Marketing Analysis”
appears somewhere on the page currently being tested. Use verifyTextPresent when you are
interested in only the text itself being present on the page. Do not use this when you also
need to test where the text occurs on the page.
verifyElementPresent
Use this command when you must test for the presence of a specific UI element, rather than
its content. This verification does not check the text, only the HTML tag. One common use is
to check for the presence of an image.
Command Target Value
verifyElementPresent //div/p/img
This command verifies that an image, specified by the existence of an <img> HTML tag, is
present on the page, and that it follows a <div> tag and a <p> tag. The first (and only)
verifyText
Use verifyText when both the text and its UI element must be tested. verifyText must use a
locator. If you choose an XPath or DOM locator, you can verify that specific text appears at a
specific location on the page relative to other UI components on the page.
Command Target Value
This is my text and it occurs right
verifyText //table/tr/td/div/p
after the div inside the table.
The following locator strategies would return the elements from the HTML snippet above
indicated by line number:
● identifier=loginForm (3)
● identifier=password (5)
● identifier=continue (6)
● continue (6)
Since the identifier type of locator is the default, the identifier= in the first three examples
above is not necessary.
4.11.2. Locating by Id
This type of locator is more limited than the identifier locator type, but also more explicit. Use
this when you know an element’s id attribute.
<html>
1 <body>
2 <form id="loginForm">
3 <input name="username" type="text" />
4 <input name="password" type="password" />
5 <input name="continue" type="submit" value="Login" />
6 <input name="continue" type="button" value="Clear" />
7 </form>
8 </body>
9 <html>
10
● id=loginForm (3)
● name=username (4)
● name=continue value=Clear (7)
● name=continue Clear (7)
● name=continue type=button (7)
Note
Unlike some types of XPath and DOM locators, the three types of locators above allow
Selenium to test a UI element independent of its location on the page. So if the page
structure and organization is altered, the test will still pass. You may or may not want to also
test whether the page structure changes. In the case where web designers frequently alter
the page, but its functionality must be regression tested, testing via id and name attributes,
or really via any HTML property, becomes very important.
● xpath=/html/body/form[1] (3) - Absolute path (would break if the HTML was changed only
slightly)
Laboratory 3 – Functional Test Automation
Academy of Economic Studies Cybernetics and Economic Informatics Faculty
● //form[1] (3) - First form element in the HTML
● xpath=//form[@id='loginForm'] (3) - The form element with attribute named ‘id’ and the
value ‘loginForm’
● xpath=//form[input/@name='username'] (3) - First form element with an input child
element with attribute named ‘name’ and the value ‘username’
● //input[@name='username'] (4) - First input element with attribute named ‘name’ and the
value ‘username’
● //form[@id='loginForm']/input[1] (4) - First input child element of the form element with
attribute named ‘id’ and the value ‘loginForm’
● //input[@name='continue'][@type='button'] (7) - Input with attribute named ‘name’ and
the value ‘continue’ and attribute named ‘type’ and the value ‘button’
● //form[@id='loginForm']/input[4] (7) - Fourth input child element of the form element
with attribute named ‘id’ and value ‘loginForm’
These examples cover some basics, but in order to learn more, the following references are
recommended:
● W3Schools XPath Tutorial
● W3C XPath Recommendation
There are also a couple of very useful Firefox Add-ons that can assist in discovering the XPath
of an element:
● XPath Checker - suggests XPath and can be used to test XPath results.
● Firebug - XPath suggestions are just one of the many powerful features of this very useful
add-on.
● link=Continue (4)
● link=Cancel (5)
Locating by DOM
The Document Object Model represents an HTML document and can be accessed using
JavaScript. This location strategy takes JavaScript that evaluates to an element on the page,
which can be simply the element’s location using the hierarchical dotted notation.
Since only dom locators start with “document”, it is not necessary to include the dom= label
when specifying a DOM locator.
1 <html>
● dom=document.getElementById('loginForm') (3)
● dom=document.forms['loginForm'] (3)
● dom=document.forms[0] (3)
● document.forms[0].username (4)
● document.forms[0].elements['username'] (4)
● document.forms[0].elements[0] (4)
● document.forms[0].elements[3] (7)
You can use Selenium itself as well as other sites and extensions to explore the DOM of your
web application. A good reference exists on W3Schools.
● css=form#loginForm (3)
● css=input[name="username"] (4)
● css=input.required[type="text"] (4)
● css=input.passfield (5)
● css=#loginForm input[type="button"] (7)
● css=#loginForm input:nth-child(2) (5)
For more information about CSS Selectors, the best place to go is the W3C publication. You’ll
find additional references there.
Note
storeElementPresent
This corresponds to verifyElementPresent. It simply stores a boolean value–
”true” or “false”–depending on whether the UI element is found.
storeEval
This command takes a script as its first parameter. Embedding JavaScript
within Selenese is covered in the next section. StoreEval allows the test to
store the result of running the script in a variable.
4.14. Refferences
http://www.seleniumhq.org/docs/02_selenium_ide.jsp
https://www.youtube.com/watch?v=IhJgrLjljpc
https://www.youtube.com/watch?v=N06S26yo8jg