Don’t Assume that Smart Is Always Smart

Smart identification is way by which QTP identifies an object when it is not found in the object repository during the run session. But it is not advisable to use this feature. Because QTP assumes and finds the object during run session, it is not a good idea to assume any think in software testing.

Let us see a simple example how QTP smart identification fails.

Scenario

I want to verify a simple web page which comes, says after I perform some transactions in a website. The web page has a simple text message “Your transaction is successful” after a successful transaction and “Your transaction is not successful” after an unsuccessful transaction. Here you are automating a scenario to check a successful transaction page exists or not after a successful transaction.

The code to check that is

If browser (“Smart is not Smart”).Page (“Smart is not Smart”).WebElement(“Your transaction is successful”).Exist Then

reporter.ReportEvent micPass,”Pass”,”Result Pass”

Else

reporter.ReportEvent micFail,”Fail”,”Result Fail”

End If

This is the sample of that page

sucessful

And the result is

pass

But now consider that the transaction is not successful and you got a message “Your transaction is not successful”

Here is the sample page

unsuccessful

But if you run the above code, the result will be still passing.

pass-warning

What cause this problem? Mr. Smart Identification

The only difference between those web element in successful and unsuccessful transaction is the text. So QTP assumes both the object is same and says pass. Yes, it gives a warning on using smart identification but it is visible only in the QTP result window. If you are using some other external means to document the result, this will never get noticed.

So it is always better to disable smart identification, the simplest way to do is go to File –>Setting–>Run tab and check “Disable Smart Identification during Run Session”

If you want to disable smart identification in you Quicktest Automation Object Model, the script is

Dim App ‘As Application

Set App = CreateObject(“QuickTest.Application”)

App.Test.Settings.Run.DisableSmartIdentification = True

Here is the result after disabling the smart identification.

fail

Advertisements

QTP Tips.txt

There is a Tips.txt present in the QTP installed directory.This has a lot of useful tips.It is present under QTP Installed Directory\dat\Tips.txt.Mostly C:\Program Files\HP\QuickTest Professional\dat

Wondering how did I miss this for so long,there are many interesting and lots of unknown tips(many might be aware of it,at least unknown to me). After uncovering this file, I googled it and found one blog referring to this file. Here is that link, he has given all the tips in the blog.

Simple Parametrization in QTP

Parameterization is used when we need to handle run time data in scripts, consider a scenario of verification of user login to gmail. We verify the user name displayed at the top right corner to make sure that the user logged is correct. But the name displayed depends on the login id used and is not static, so we need to parameterize the value.
Parameterization may be done by passing values as variable or through data sheet. It is always a good practice to user data sheet, so that editing the data during play back and maintenance will be easier.
Below is the sample code for parameterization through variables
Id = “<emailid@gmail.com>”
Pwd= “<password>”
Browser(“Google”).Page(“Google”).Link(“Sign in”).Click
Browser(“Google”).Page(“Google Accounts”).WebEdit(“Email”).Set(Id)
Browser(“Google”).Page(“Google Accounts”).WebEdit(“Passwd”).SetSecure(Pwd)
Browser(“Google”).Page(“Google Accounts”).WebButton(“Sign in”).Click
‘ Verification point verifies whether used has successfully logged in by checking the email displayed after logging in
Login = Browser(“Google”).Page(“iGoogle”).WebElement(“innertext:=”&Id).GetTOProperty(“innertext”)
msgbox(Login)
If Login=Id Then
Browser(“Google”).Page(“Google”).Link(“iGoogle”).Click
Browser(“Google”).Page(“iGoogle”).Link(“innertext:=Sign Out”).Click
Else
msgbox(“Login Failed”)
End If
Below is the sample code for parameterization through datasheet
Browser(“Google”).Page(“Google”).Link(“Sign in”).Click
Browser(“Google”).Page(“Google Accounts”).WebEdit(“Email”).Set(DataTable(“EmailID”, dtGlobalSheet))
Browser(“Google”).Page(“Google Accounts”).WebEdit(“Passwd”).SetSecure(DataTable(“Password”, dtGlobalSheet))
Browser(“Google”).Page(“Google Accounts”).WebButton(“Sign in”).Click
‘ Verification point verifies whether used has successfully logged in by checking the email displayed after logging in
Login = Browser(“Google”).Page(“iGoogle”).WebElement(“innertext:=”&DataTable(“EmailID “, dtGlobalSheet)).GetROProperty(“innertext”)
msgbox(DataTable(“EmailID”, dtGlobalSheet))
If Login=DataTable(“EmailID”, dtGlobalSheet) Then
Browser(“Google”).Page(“Google”).Link(“iGoogle”).Click
Browser(“Google”).Page(“iGoogle”).Link(“innertext:=Sign Out”).Click
Else
Message = Browser(“Google”).Page(“Google Accounts”).Webelement(“html id:=errormsg_0_Passwd”).GetROProperty(“innertext”)
msgbox(Message)
If Message = “Username and password do not match” Then
msgbox(“Login Failed”)
Else
msgbox(“Invalid Error message”)
End If
End If

Parameterization is used when we need to handle run time data in scripts, consider a scenario of verification of user login to gmail. We verify the user name displayed at the top right corner to make sure that the user logged is correct. But the name displayed depends on the login id used and is not static, so we need to parameterize the value.

Parameterization may be done by passing values as variable or through data sheet. It is always a good practice to user data sheet, so that editing the data during play back and maintenance will be easier.

Below is the sample code for parameterization through variables

Id = “<emailid@gmail.com>”

Pwd= “<password>”

Browser(“Google”).Page(“Google”).Link(“Sign in”).Click

Browser(“Google”).Page(“Google Accounts”).WebEdit(“Email”).Set(Id)

Browser(“Google”).Page(“Google Accounts”).WebEdit(“Passwd”).SetSecure(Pwd)

Browser(“Google”).Page(“Google Accounts”).WebButton(“Sign in”).Click

‘ Verification point verifies whether used has successfully logged in by checking the email displayed after logging in

Login = Browser(“Google”).Page(“iGoogle”).WebElement(“innertext:=”&Id).GetTOProperty(“innertext”)

msgbox(Login)

If Login=Id Then

Browser(“Google”).Page(“Google”).Link(“iGoogle”).Click

Browser(“Google”).Page(“iGoogle”).Link(“innertext:=Sign Out”).Click

Else

msgbox(“Login Failed”)

End If

Below is the sample code for parameterization through datasheet

Browser(“Google”).Page(“Google”).Link(“Sign in”).Click

Browser(“Google”).Page(“Google Accounts”).WebEdit(“Email”).Set(DataTable(“EmailID”, dtGlobalSheet))

Browser(“Google”).Page(“Google Accounts”).WebEdit(“Passwd”).SetSecure(DataTable(“Password”, dtGlobalSheet))

Browser(“Google”).Page(“Google Accounts”).WebButton(“Sign in”).Click

‘ Verification point verifies whether used has successfully logged in by checking the email displayed after logging in

Login = Browser(“Google”).Page(“iGoogle”).WebElement(“innertext:=”&DataTable(“EmailID “, dtGlobalSheet)).GetROProperty(“innertext”)

msgbox(DataTable(“EmailID”, dtGlobalSheet))

If Login=DataTable(“EmailID”, dtGlobalSheet) Then

Browser(“Google”).Page(“Google”).Link(“iGoogle”).Click

Browser(“Google”).Page(“iGoogle”).Link(“innertext:=Sign Out”).Click

Else

Message = Browser(“Google”).Page(“Google Accounts”).Webelement(“html id:=errormsg_0_Passwd”).GetROProperty(“innertext”)

msgbox(Message)

If Message = “Username and password do not match” Then

msgbox(“Login Failed”)

Else

msgbox(“Invalid Error message”)

End If

End If

What is Regular Expression?

What is Regular Expression?

Regular expression is a set of symbols (characters) and syntactic elements used to match patterns of text. The term regular expression is often abbreviated to regex or RE.

A regular expression is a way of describing a string of text using metacharacters or wildcard symbols.

A regular expression, often called a pattern, is an expression that describes a set of strings. They are usually used to give a concise description of a set, without having to list all elements.

Quantification:

A quantifier after a token (such as a character) or group specifies how often that preceding element is allowed to occur. Given below are most commonly used quantifiers

1. Period (.) – Matches one character in its position any character(including numbers,special    characters) other than /n(new line)
Example : welcome.qtp matches “welcome@qtp”,”welcome2qtp”,”welcome qtp” but not “welcomeqtp”
2. QuestionMark(?) – Matches zero or one occurances of previous character.
Example: goo?gle matches “gogle” and “google”
3. Asterisks(*) – Matches zero,one or many occurances of previous character.
Example: goo*gle matches “gogle”, “google”,”gooogle”,”gooooooooooooooooooogle” etc..
4. Plus(+) – Matches one or more occurances of previous character.
Example: goo+gle matches “google”,”gooogle” etc.. but not gogle
5. Backslash (\): It can be used in conjunction with a special character to indicate that the next character be treated as a literal character
Example: welcomenew\* will literally match “welcomenew*”
6. Caret (^) – Match any character in the list except for the ones specified in the string
Example: [^c]at matches other than cat like bat,rat,@at,2at etc..
7. Pipe (|) – Logical OR
Example: (c|r)at matches cat or rat
8. Square Braces([]) – Matches the range for anything under that range
Example : [a-z] all lower case,[A-Z] all upper case,[0-9] numbers for 0 to 9

Let us try to come up with a regular expression which allows numbers from 0 to 1200 (this is given in QTP help).We can solve this by having three different patterns first for 0-999,1000-1199 and 1200

( [0-9][0-9][0-9] | [1][01][0-9][0-9] | 1200),but the problem here is it will allow to only enter four digits ,so 7 should be entered as 0007 similarly 77 as 0077,so to solve that use ? Quantifier ([0-9]?[0-9]?[0-9] | [1][01][0-9][0-9] | 1200).

The Regex Coach is a graphical application for Windows which can be used to experiment with regular expressions interactively. You can download this from http://weitz.de/regex-coach/

OOPS! This is the Fundamental for Automation

Understanding the OOPS is the foundation for automation. This doesn’t mean that as an automation engineer you should have very strong knowledge in OOPS like any other programmer. All you should know is very basics like Class, Object and its Method and Properties to begin with.

Most of the automation tool identifies every object (like edit box, button, and drop down) by the properties and perform action on those objects with the available methods (like Set, Click, and Select).

To begin let us start with understanding what is a class in OOPS world

It is a blue print from which we can build similar Objects, it is a container used to group related attributes (properties) and methods.

So what is an Object?

Before OOPS, code and data were kept separately. For example, in the C language, units of code are called functions and units of data are called structures. But, in object oriented programming, code and data are merged into a same, called an object.

To make it more clear,An Object is basically program hiding in a ‘box’. Almost every visual key you use in a software program is an object. Objects can be clicked, accessed via keyboard, by mouse-over, joystick, steering wheel, etc…Even the tool bar, back button of your browser is an object. Object is a box that hides program in it, and interact with user.

For us Back button is just a button, on which we can click, it takes you to previous page. But for automation tool Back button, is an object derived from class Button.We click on the back button to go to previous page, because we know that button can be clicked, but then how browser knows that on clicking Back button it should go back to previous page not to refresh page? Because back button has certain properties associated with it, which tells the browser that on click of this button do certain actions.

Method is nothing but the action that can be performed on that object

Property is the attributes or characteristics of that Object.

Hope you get some idea now, on why you need to understand OOPS for automation.

The same logic holds good when we use automation tools. The tool we use identifies and stores those object into object repository (in QTP),so when we run the script it compares the current object properties with the stored one to identify the right object on which the action needs to be performed. The Method tells what the action should to be .

The code to click on Google Search button in QTP looks

Browser (“Google”).Page (“Google”).WebButton (“Google Search”).Click

So here Browser, Page and WebButton are Class,First Google inside quotes is Object of class Browser,second Google is object of Class Page ,Google Search is object of Class Webbutton.These are stored into object repository(in QTP). Click is the method that you are going to use to click the button.

Summary:

Class: It is a blue print from which you create object

Object: Almost every thing you see on the computer screen is an object

Method: Tell us the actions, which can be performed on the object

Property: Attributes that define or help to identify an object

Next to Read : Object Repository and Descriptive Programming in QTP

Getting Started With Automation Testing

“Test automation shouldn’t be a goal; test automation helps you achieve goals” -Jonathan Kohl. Read More Here

Many think that,the place to start learning the art of Automation is the tool one uses.But with my experience I would say that the place to start is OOPS.Then understand the basics of technology in which the application is developed. For example,If you are automating a web based application,then be familiar with HTML,DCOM,COM,DHTML.

Get some working knowledge on SQL, Connecting to DB through the automation tool,XML,FSO (to interact with files) and COM objects of MS Excel(read and write data to excel sheet),MS Outlook(to e-mail reports)

Then get to know the coding language or script tool uses,then understand how the tool recognize your application, get to know the available functions.

Now your are ready to automate your application,now decide on the Automation Framework ,come up with Automation test plan and Estimations(separate article coming soon )

Read this link on more details about getting started with automation.

Addendum Added on Oct 2.2009 : Please  read Testing Vs Checking by Michael Bolton before jumping into automation