Test Automation Using Unified Functional Testing Preview
Test Automation Using Unified Functional Testing Preview
Testing
Version: 11.50
Navneesh Garg
Step by step guide
Learn automation on a web
based application
interview questions
Contents
About the Author ...................................................................................................... 7
Preface....................................................................................................................... 8
1. Introduction to Automation................................................................................ 11
1.1 What is Functional Automation?..............................................................................11
1.2 Why do we Automate?.............................................................................................12
1.3 When should we Automate? Economics of Automation...........................................13
1.4 Commercial and Open Source Automation Tools....................................................14
2. UFT Installation and Sample Application Walkthrough...................................... 16
2.1 HP Unified Functional Testing Software Setup Instructions.....................................16
2.2 Sample Application Walkthrough . ..........................................................................21
3. Planning before Automation................................................................................ 27
3.1 Pre-Requisite Before you Start Recording.................................................................27
3.2 Test Automation Process .........................................................................................31
4. Create your First Script........................................................................................ 32
4.1 Launch UFT and Understanding UFT Interface......................................................32
4.2 Set UFT Web Page Frame Option Settings...............................................................36
4.3 Recording Script......................................................................................................37
4.4 Tips for any web Recording Issues............................................................................41
4.5 Replay Script............................................................................................................41
4.6 Save Script................................................................................................................43
5. Managing User Interface Controls....................................................................... 46
5.1 How Does UFT Replay Scripts................................................................................46
5.2 Using Object Repository..........................................................................................47
5.3 Add objects to Object Repository.............................................................................49
Contents
Preface
My motivation for writing this book stems from my hands on experience in the IT and
testing industry and the experience I have gained as an automation consultant working in
numerous complex automation projects. It disheartens me when I come across automation
and frameworks being implemented in a very novice fashion with basic automation
principles and guidelines not adhered to. In such cases, rather than automation providing a
true advantage to these practitioners, it leads to major maintenance effort and automation
failures. Of course it leads to a loss of faith too in test automation as a test activity.
The key objective of this book is to get the audience to understand, the in depth internals
of automation, without getting into a lot of theory.
Scope of Topics
HP recently launched the new version 11.5 of QuickTest Professional (QTP). In this new
version, traditional QTP has been combined with HP Service Test (which was a separate
tool to test web services and API). Hence, this new version is called HP UFT (Unified
Functional Testing). UFT has all the same features, which QTP 11.0 had and more. We
will be using the word UFT or QTP interchangeably through the book. HP Service Test
features are out of scope of this book.
As part of scope of this book we will primarily discuss GUI based Tests, which are similar
to QuickTest Tests in previous versions of QTP. API tests, Business Process Test, and
Business Process Flow, are not in the scope of the book.
Any references made to HP QTP in this book, refer to features of QuickTest Professional
version 11.0
My intent here in this book is to teach all the key features of UFT, and cover all crucial
aspects of the same, which are used to create effective automation frameworks.
Key Audience
The target audience for this book are functional testers and beginner test engineers, who
want to learn UFT quickly and in the right way, which will help them create an effective
automation framework.
Preface
Acknowledgements
I would like to thank my family (my parents, my wife Sapna, my wonderful kids Shaurya
and Adaa) for the continued support given to me, without whom this book would not
have been possible.
Special thanks to S. Constncio Colao and Philip Smith for their reviews and feedback,
which immensely helped as I worked on this book.
I would also like to thank my colleagues and clients for the inspiration, knowledge, and
learning opportunities provided.
2
10
Introduction to Automation
Introduction
In this chapter we will talk about automation fundamentals and understand what
automation is and why we need automation. Another important objective of this chapter is
to understand the economics of automation and determine when we should do automation
in our projects. We will also get an insight on a few popular commercial and open source
automation tools available in the market.
Key objectives:
What is automation?
Why automate? What are the benefits of automation?
Economics of automation.
Commercial and Open Source automation Tools.
11
12
18. You can read the Readme file, which opens automatically.
19. You can now access HP UFT from Start -> All Programs HP Software HP
Unified Functional Testing HP Unified Functional Testing
20. If you are using the trial version of the software, you will get License Expiration
warning dialog, once you launch HP UFT. Click on Continue to keep using the
tool for the trial duration.
Note: If you do not see Continue button in the license expiration dialog (instead you see
Cancel button) , it is possible that you might have a previous version of HP QuickTest
installed on the machine, because of which you would not be able to use the trial software.
There is no workaround. In that case you cannot use trial version of the software on that
machine, and you would need to purchase the software.
Note: Refer to HP UFT Installation guide, in case you need more detailed steps or face
any issues with installation.
Our sample application is a simple hotel booking web application, which has the following
key features
Search for Hotel
Book a Hotel
View Itinerary
Cancel Booking
Let us browse through the application
1. Launch IE and enter URL www.adactin.com/HotelApp to see Login page.
3. Register yourself by entering all the fields. Remember the username and password
as you will be using this username/password to login to application and remaining
part of automation.
4. After you register, an automatic email will be sent to your email-id for confirmation.
Incase you do not receive the email, re-verify it in junk folder as email might have
gone to your junk folder.
5. Click on the confirmation link in email
6. Go to Login page link.
7. On the Login page use the username/password with which you have registered
earlier, and click on the Login page. You will come to Search Hotel Page.
8. Search for Hoteli. Select a location e.g. Sydney
ii. Select room nos. e.g. 2
iii. Select adult rooms e.g.2
iv. Click on Search button
9. Select a Hoteli. Select one of the Hotel Radio Button, e.g. select radio button next to Hotel Cornice
23
3. In the Record and Run settings dialog, select Web Tab and select Record and run
test on any open browser.
Record and run test on any open browser: This option enables you to record and run on
any browsers which are open. This is the most common and widely used option.
Open the following address when a record or run session begins: You can define specific
URL that you would like to open when your script records or runs. This is not a frequently
used option.
4. Click OK.
Now you are in recording mode. Anything you do from now on will be recorded as an
action in UFT script. You would see a red Recording GUITest1 flashing dialog comes,
giving an indication you are in recording mode.
5. Assuming that application is already open in IE browser with login page visible, and
perform below steps.
a. Login (Use the username/password with which you have registered earlier).
b. Search for Hotel.
i. Select a location e.g. Sydney
ii. Select room no: e.g. 2
iii. Select adult rooms e.g.2
iv. Click on Search button
c. Select a Hotel.
i. Select one of the Hotel Radio button e.g. select radio button next to Hotel
Creek
d. Book a Hotel.
i. Enter First Name
ii. Enter Last Name
iii. Enter Address
iv. Enter 16 digit Credit card no:
v. Enter Credit card type
vi. Enter Expiry Month
vii. Enter ExpiryYear
viii. Enter CVV number
ix. Click on Book now
38
Example
Let us take an example:
I worked for one of our retail domain client, which had more than 2000 stores in the
country, as part of testing and automation team. They developed a point of sales system
and once this was manually tested, they gave us a list of more than 10000 username and
password pairs, and asked us to set them up in the system. As a testing team, our task
was to verify if all usernames and passwords are setup correctly. We were given a target of
.01% failure threshold. If we have to verify all this manually, assuming we would verify 1
username/password combination every 1 minute (as there were couple of validations we
had to do once logged in), it would have taken us 5000 minutes or approximately 20-24
days of man effort, get the idea of how laborious and time consuming that task would be?
Solution: Wouldnt it be great if you have a script using which I could pick up the first
username and password entered from an excel sheet, log the user in and perform all the
validations and all of this without manual intervention?
An even better solution, if we could create a script to iterate across all the 10000 usernames
and passwords, wouldnt that be a better solution. This is exactly what did, we created
an automation script using UFT, which took us less than 4 hours to develop , ran it
overnight, got the failed records, again re-tested the records once fixed and delivered it to
the customer with 0% issues. The concept of running the same script with multiple dataset
values is called Parameterization.
Any test case, which needs to be executed multiple times with different data values are ideal
candidates for automation.
Key objectives of this chapter are:
How to Parameterize my Script.
Script Execution and Result Analysis.
55
3. Make sure you are in Keyword view of UFT (Select View Keyword View).
4. Locate the line with Item location in the Keyword view.
5. Go to column value next to location line and click in the value column, and select
the city.
56
10
Example
At one of our clients, where we had to implement automation, we were given 100 existing
automation scripts created using QTP/UFT. We were told they used to work 3 months
back, but now, after they were run on new builds, they fail. We were asked to fix the
scripts. Guess what we found? All the scripts were using local object repository. When
we identified the objects that were causing the script to fail, we discovered that the same
object was used in all 100 scripts. So the object had to be modified at least 100 times as it
was being used in all the scripts. But there were at least 100 objects, which had changed.
Adding to this, they informed us that UI changes were still happening and that the objects
will change again. Our recommendation to them was to hold-on and to re-do the scripts
using shared object repository, since the same effort that we would invest now would be
required again when we get a new application build, with updated objects. Yes, it did
mean that most of the previous effort already done had been wasted, but our re-scripting
approach using a shared object repository approach made sure scripts maintenance worthy
for future.
86
In this chapter we will discuss how to create and add objects to shared object repository,
and how to maintain the shared object repository.
Key Objectives
Create and add objects to Shared Object Repository
Rename logical names of objects
Associate Shared Repository to script
Recording of script using Shared Repository
Note: We will create/modify shared object repository using Object Repository manager.
87
12
VBScript Fundamentals
VBScript is the scripting language used in UFT editor view. We can write any VBScript
statement in UFT editor view and it will be executed. This makes UFT very powerful.
VBScript being a global language, we can find plenty of sample code on Google and use it
in our UFT GUI script.
Example
Recently we automated some scenarios where we had to create an automation test report
in a MS Word document format with all snapshots, which we had to forward to the
development and business team. We used VBScript and MS Word object model to easily
accomplish this.
Using VBScript we can interact with external third party applications (Word, Excel, PDF,
Text file, Database), and write custom code in our script, which make our script more
intelligent and worthwhile.
Having said this, VBScript is still a very simple language. We do not use any complex
pointers, data structures, exception handing blocks or object instantiation constructs.
Many testers fear using complicated programming principles. This makes UFT very easy
to use, by not only programming experts but also by functional testers or business analysts.
Key Objectives:
VBScript Basics and data types
VBScript Conditional Statement, Loop Statements, Procedures
Commonly used VBScript string functions
Sample VBScript programs
VBScript Fundamentals
Windows Script
VBScript talks to host applications using windows script. With windows script, browsers, and
other host applications do not require special integration code for each scripting component.
Windows script enables a host to compile scripts, obtain and call entry points, and manage
the namespace available to the developer. Microsoft provides run-time support for VBScript.
Data Types:
What is a Variable?
A variable is a name given to a location in memory, where some data used by a program is
stored. You can refer to a variable by name to see or to change its value.
Variables can hold different types of data: numbers, characters, strings, and some special
complex data. These categories are called data types.
VBScript keeps it simple. In VBScript there is only one datatype Variant. In this variant
type, you can store numbers, characters, strings, boolean and other data types. Surely this
makes things simpler!
For example: The books detail of a library, stores the id of the book, and name of the book
and for storing these data sets it uses variables.
book_id
book_name
VBScript is a loosely typed language, which means you do not have to declare the variables
before using them in your scripts.
Rules for Variable Names:
Must begin with a letter
Cannot contain a period (.)
Cannot exceed 255 characters
111
3. Next step is to add Order No. field into Object Repository. Manually browse
through the application so that you can see Order No. object.
4. Go to Resources Object Repository and Click on Add objects button and Add
Order Number object.
137
15
Reporter Object
and Custom Checkpoint
In one of the previous chapters, we looked into how UFT provides standard checkpoint
and others type of checkpoints, to verify functional correctness of the application. This is
done at the basic level.
At an advanced level, we use custom checkpoints to verify the correctness of the application.
What we mean by custom checkpoint is that using scripting we can manually compare our
expected value with actual value and pass/fail the script. Now why do we need to do that?
Reason is that it gives us more flexibility to manipulate the expected and actual values and
compare values at will.
Example
We were once automating an accounting based application package. We had to test the
reports feature of the application. For instance, if we had to verify the profit and loss report
for a particular account, we had to first calculate the expected value from what was setup in
various forms in the application, and fetch the actual value from reports and then perform
comparisons. Now, we had to do this for lot of values we saw this in the report. Custom
checkpoint made it lot earlier and flexible for us to perform these kinds of checks, because
we could perform computation of expected values and also create loop statements to verify
multiple values in the same script. This would have been hard using standard checkpoint
as it did not allow runtime computations of expected values and we would have to add so
many standard checkpoints.
Note: You can replace standard checkpoints and use just custom
checkpoints.
In this chapter, we will see how to add a custom checkpoint. One of the key utility objects,
which well use in this chapter, will be the Reporter Object. This object helps us to report
pass, fail, or informational messages from within the script.
Key Objectives
Reporter Object and ReportEvent Method Syntax
Apply Custom Checkpoints on a Test Scenario
142
Syntax
Reporter.ReportEvent EventStatus, ReportStepName, Details [, Reporter
Argument
EventStatus
Type
Number or
pre-defined
constant
Description
Status of the report step:
0 or micPass: Causes the status of this step to
be passed and sends the specified message to the
report.
1 or micFail: Causes the status of this step to
be failed and sends the specified message to the
report. When this step runs, the test fails.
2 or micDone: Sends a message to the report
without affecting the pass/fail status of the test.
ReportStepName String
Details
String
ImageFilePath
String
Example
The following examples use the ReportEvent method to report a failed step.
143
5. Go to Editor View in UFT GUI Test script and we will use ImportSheet Method to
Import Data from Excel Sheet.
ImportSheet Method
This method imports a sheet of a specified file, to a specified sheet in the run-time data
table. Using this method we can import the data in our external excel file and get that data
into the UFT scripts built-in data table.
The column headings in the sheet you import must match the data table parameter names
in the action, for which the sheet is being imported. Otherwise, your test or component
may fail.
Syntax
DataTab.ImportSheet(FileName, SheetSource, SheetDest)
Argument
FileName
Type
String
Description
The full path of the Excel table from which you want
to import a sheet.
SheetSource Variant The name or index of the sheet in the file that you
want to import. Index values begin with 1.
SheetDest
Variant The name or index of the sheet in the Data Table that
you want to replace with the SheetSource. Index values
begin with 1.
Example
The following example uses the ImportSheet method to import the first sheet of the name.xls
table to the name sheet in the tests run-time data table.
DataTable.ImportSheet C:\name.xls ,1 ,name
So let us go in the Editor view of our script and type below statement to import login data
into our script.
DataTable.ImportSheet D:\UFT\\Login.xls, 1, 1
Note: Please make sure to change the path based on, where you have stored the sheet. Your
editor view code will look like below.
158
22
Example
We have used the combination of QC/ALM with UFT at number of our client places. Most
recently we had setup an automation framework for a client having a learning management
system. We created an automation framework for them, stored all our UFT scripts in QC/
ALM and executed the scripts from QC/ALM. This made the knowledge transfer to the
client team very simple, as they knew that all their scripts and test results are within QC/
ALM. All they needed to do was to click a button to execute the UFT scripts from QC/
ALM.
As part of this chapter we will cover how we can store UFT scripts in QC/ALM and how
to execute automation scripts from QC/ALM.
Key Objectives
UFT QC/ALM integration setup
Saving UFT script in QC/ALM from UFT
Launching UFT script from QC/ALM
UFT script execution from QC/ALM
207
1. We should be able to access QC/ALM client on that machine (assuming that you
already have QC/ALM server installed).
2. We need to have UFT installed on that machine.
3. We need to install UFT add-ins for QC/ALM on that machine. Although there is
backward compatibility of UFT with older versions of QC/ALM, it is advisable to
install and integrate UFT and QC/ALM of same versions. You will find UFT addin for QC/ALM in the UFT installation itself.
a. You will find the add-ins once you start UFT Setup file.
Note: Make sure you have admin rights to install this add-in on your machine.
4. Once you install this add-ins, Launch UFT.
5. Go to Tool > Options GUI Testing Test Runs. Make sure that checkbox
Allow other HP products to run tests and components is checked. Close the
dialog after selection.
25
This is a great enhancement from previous versions of QTP, where users could not open
multiple tests at the same time.
Error pane
The Errors pane displays a list of errors generated when opening, working with, saving, or
running tests, components, function libraries, and user code files.
The Errors pane reports the following types of errors:
Code syntax errors
Missing resources (GUI testing only)
Missing references (API testing only)
Missing property values (API testing only)
Code syntax errors in previous versions of QTP were shown in Information pane, which is
now removed. Also missing resources pane has been removed and replaced with composite
error pane.
Automatically export test results
You can instruct UFT to automatically export run results in HTML or PDF format after
every run session. Select Tools > Options > General tab > Run Sessions to set your
preferences for the export.
In previous versions of QTP, the user had to manually export the results to HTML or
pdf format.
Select License Types From Within the Add-in Manager Dialog box
If your concurrent license server has more than one valid license type installed, you can
select the license you want to use in the add-in Manager dialog box. You have the option
to choose a different license each time you open UFT (By default, your selection from the
previous session is used).
230
28
246
This suppresses only the results window, but a log will be created and can be accessed if
required from View Last Run Results menu
How to open an application using VBScript in UFT Editor View?
Use SystemUtil object to open and close applications and processes during a run session.
A SystemUtil.Run statement is automatically added to your test when you run an
application from the Windows Start menu or the Run dialog box while recording a test. If
it is not added, you can add it manually and specify the path of the .exe file to be executed
as an argument. Below is a very common example to open Internet Explorer
Example:
SystemUtil.Run C:\Program Files\Internet Explorer\iexplore.exe,www.google.com,C:\
Documents and Settings\Administrator,open
How do we handle run-time errors or exceptions in UFT?
There are two ways how run-time errors can be handled. We can create a recovery scenario
and link it to every script or we can use On Error Resume next statement.
On Error Resume Next causes execution to continue to the statement immediately
following the statement that caused the run-time error, or with the statement immediately
following the most recent call out of the procedure containing the On Error Resume
Next statement. This allows execution to continue despite of a run-time error.