Quick Test Pro:-An Introduction


If you would like to know what automation actually means , refer the link below:-www.satisfice.com/articles/test_automation_snake_oil.pdf [Automation Snake Oil by James Bach]

What is QTP ?

QTP–> stands for Quick Test Professional.It is an automated graphical user interface functional and regression testing tool which allows the automation of web based and client based computer applications running on Microsoft Windows.

It uses VBScript as it’s scripting language, but VBScript supports classes but not polymorphism and inheritance.Different Add-ins are available for custom testing.QTP does not support Java  appln.. unless Java add-in is installed.
QTP is usually used for “UI Based” Test Case Automation, it can automate some “Non-UI” based Test Cases. (e.g. API (Certification testing), Database Testing, etc.)
QTP is an advanced version of Winrunner,hence it works together with Winrunner and Quality center.
Limitations:It cannot be used on non-window based application,since it fetches object like Activex from Windows Appllication,and Remote desktop connection is not possible due to licensing issue.
Some well known Versions:QTP 8.2, 9.0, 9.1, 9.2, 9.5,10
Supported Browsers:IE
IE,Firefox,Netscape
Recording:IE
Played:IE,Firefox,Netscape,firefox3(q-10)
Versions Released Date/Year
11.0 2010
10.0 Feb 2009
9.5 Feb 2008
9.2 Feb 2007
9.1 Jan 2007
9.0 -2006
8.0 Jan 2004
6.5 Mar 2004

I greatly appreciate any comments on how i can improve this blog.So please feel free to write to me.

QTP Lab:- A touch of madness!

Add attachment in QC


Script to upload attachment in QC test lab:
Dim oCurrentTest,oAttachment
Set oCurrentTest = QCUtil.CurrentTest.Attachments
Set oAttachment = oCurrentTest.AddItem(Null)
oAttachment.FileName = “C:\Results.xls”
oAttachment.Type = 1
oAttachment.Post
oAttachment.Refresh
Set oAttachment =Nothing
Set oCurrentTest =Nothing

What is Business Process Testing?


BPT, well, I’ve heard this term 2yrs back. Since then I kept wandering about it’s implementation and wondering about it’s development, until one fine day my offshore manager asked me to learn & implement BPT for a pilot run .

I straight jumped into the QTP help file repository and browse some links related to BPT.The first sentence i had stumbled upon was “Subject matter experts creates an automation test”, re-read the sentence twice, thrice and more and closed the help file as the very first sentence  seemed to be  weird . Having been working with Keyword and Data driven framework , I felt  it’s not worth to concentrate more on this topic.

I kept on wondering about the issues I faced in script development and thought about the SME (one from my department )  creating an automated test and thought about my collegues just adding objects to OR and watching SME creating the test.

I went outside bhabhi ki tapri (Our Hangout Place) , had tea and puffed,suddenly one thought striked my mind:-

We believe that if men have the talent to invent new machines that put men out of work, they have the talent to put those men back to work-Kennedy”

and my exploration and journey begun…..All I can say now is BPT is a wonderful concept and an amazing cost saving component oriented approach of automation.

 What is Business Process Testing?

BPT stands for Business Process Testing.It’s a component oriented approach to automation. It provides a script-free mechanism for business analysts to design and align tests with business processes for accurate functionality coverage, while allowing automation test engineers to focus on the automation stuffs.

HP Business Processing Testing Framework Key benefits:-

* Implement a framework for building reusable, data-driven test components

* Convert manual tests into manual components for instantly reusable test assets

* Support manual and scriptless automated components

* Use auto-documentation to make it easy for new testers to pick up test execution

* Create and update tests for SAP and Oracle using extended capabilities

In short, it closes a gap between the business people who design the business processes and the technical people who designs and develop the automation stuffs.It would be easier to maintain the components rather than the test.Eg, If a piece of functionality changed in an application, each of the test doesn’t have to be debugged/corrected, only the component associated with that test needs to be checked.( Maintainablity)

i.e Fix one,reflects everywhere!

Who does what?

AE (Automation engineer):

  • Design Test Automation Architecture
  • Create Application Area (Area in QTP/QC where .Qfl, .Qrs and .Tsr files are created and saved)
  • Create a function library (Common functions)
  • Create OR, add objects , rename it accordingly.
  • Create Recovery Scenario and finally
  • Create business component as assigned.( egLogin, Logoff etc)

SME/BA:

  • Define business component
  • Drag components to create business process (Business process is a sequential flow of the components/scenarios to be testes)
  • Asks AE to create custom components if needed for complex or logical scenario.
  • Run the test.

More to come..keep watching this space….. :)

How to run QTP when system is locked?


How to run QTP when system is locked?

Go to start>Run>Regedit>

Change the following registry settings:-

Step 1:Goto HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest
Step 2:Locate the key “SkipEnvironmentChecks”
step 3:Change the value to “1″ (Default value is 0)
Step 4:Restart the QTP.

Now QTP should run with system locked.(make sure unnecessary pop ups are disabled)

Run QTP when system is locked

Run QTP when system is locked

Dynamically wait an object in an application


“Dynamically wait an object in an application”

It known to all that scripts written for web application suffers a lot
when it comes to Wait() or Syc().Wait() statement waits for 10 sec which is
not recommended and wait(1),wait(2)..wait(n) cannot add any value if script has
to cope with multiple rows of data.Lets take an example.

No or rows(in data sheet) to process =300
Function retrievetransno()
Wait(2)
End function
If above function is called in each iteration, image how much execution
time is wasted.

2*300=600 sec
600/60=10 min

10 mins execution time is wasted if we are going to use wait statement.
If wait() is used then it’s more pathetic:
10*300=3000 sec
3000/60=50 min

Following function could be used to overcome the above issue.It dynamically
waits and check the status of the object within the given time limit and
exits out if the object is not present within that time limit.
1*300=300 sec
300/60=5 mins

Lets start with:

'===================================================================================================
'Function:ObjectChecker
'Purpose: Lets you dynamically wait the presence of an object in an application
'Arguments: vObj,iCounter
'@vObj:Test object
'@iCounter:Maximum no of seconds (to wait)
'Author: Bibek Khatiwara
'Created on: 15th june 2011
'===================================================================================================
Function ObjectChecker (vObj,iCounter)

vObjStatus = False
Flag = 0
Do
Flag = Flag+1
If vObj.Exist(1) Then
Reporter.ReportEvent micDone ,"Wait time calc","Seacrh text box displayed in "&Flag&" second(s)"
vObjStatus = True
Else
If Flag = iCounter Then
Exit Do
End If
End If
Loop Until vObjStatus = True
ObjectChecker = vObjStatus

End Function

'Usage(sample):
Set oTxtbox=Browser("name:=google.*").Page("title:=google.*").WebEdit("name:=q")
ObjectChecker oTxtbox ,10
Set oTxtbox=Nothing

Keyword driven framework architecture in QTP


Framework:A hypothetical description of a complex entity or process-Word Web.

Here, word hypothetical makes it clear that it’s based primarily on surmise rather than adequate evidence.There are no rules and standards on test framework development.It varies from organization to organization and from team to team.Project internal architecture provides a great source of information for organizing the components of our framework.Testing components needs to be well organized to accomplish the task effectively,efficiently and in a systematic order.

We need to develop framework in a way that leads to accomplish the task without much human intervention.The heart of “Keyword driven test automation framework” is common functions that resides within the function library and the keyword acts as  it’s brain.Framework must be enough flexible to run with the desired keyword from the pool of available keywords.

well,It’s been my passion to play with electronic chips since my childhood.I can even survive in desert if i get electronic scarps and a screwdriver ;) Hence,I decided to develop a flexible framework looking at the architecture of RADIO that have been rusted on my bedroom for years.

The component used & it’s analogy with RADIO:

QTP has it’s own limitation for loading resources;as it does not allow to load .QRS file in run time,here,it goes off the track from radio tuning mechanism.Once radio is turned on we tune to different stations and adjust it’s volume and rotate/pull up-down it’s antenna to have a clarity.

Here we do just opposite, we first do the appropriate setting and proceed with further run.

How keyword driven framework works:

1.Plug in to environment.

2.Do a little bit settings on test_environment setting file;eg,paths of resources,email configuration,project url,expected time etc.

3.Search & Select appropriate generic keywords from keyword pool.

4.Go

Radio analogy:

1.Plug in to switch board.

2.Search for station

3.Set the volume and adjust the antenna

4.Turn on.

(normally 4 comes before step 2)

1.. 2 …3… Go……..! that’s it.

Details of the Component Architecture are as follows: [Note:the architecture is based on my own assumption(analogy with RADIO),if you find it uncomfortable,kindly scold me :) with your invaluable suggestions]

Keyword driven framework architecture in qtp

1.Start.Exe: Starts the tool using AOM and pass the control to Driver.

2.Application Scenarios: Test plan,test case and test steps.

3.Test Object Description: Pool of test object properties and description.

4.Resources: Repository files for application dependent functions.

5:Mytest: Driver script resides.

6: Session manager: manages the session of the test run & helps in recovery if run is unsuccessful due to some unforeseen events.

7.Test Environment_Config settings: Test run settings. (application specific)

8.Func Library: Common functions and application dependent functions separately.

9:Recovery Files: .QRS or custom recovery functions.

10:Run Results: Application run results.

11:Help files: help files and framework documentations.

Following are my tweets so far (on framework development):

Automation framework rule #1:If it’s not simple, it won’t work! if it’s simple it’s fun to use.

Automation Framework rule #2:Achieving 100% automatic tests is an unreachable goal,never dream it.

Automation framework rule# 3:Make it easier to discover the errors that occur.

Automation Framework Rule #4:Focus on stability;the more stable the design, the lower the maintenance cost.

You must have realized as of now  that framework is just a wrapper around complex internal architecture to have

a great drive with less interruption.Let turn on your radio coz you need not to know how it’s playing.Stakeholders

should play with our flexible framework  just as we tune/play our radio.

Friend,Join us on twitter for more discussions.

Non-Traditional Way to sort an array in QTP,Vbscript


“Is there any method to sort an array in VBScript?”

As VBScripter doesn’t have any inbuilt VBScript function to sort an array,we need to follow the same algorithm of Bubble sort,Selection sort,Quick sort etc.. we can overcome this limitations using .Net Class method.

well,if you have .NET Framework installed on your PC then you’ve won already :) [You need not worry for above version of QTP]

Firstly,we need to create an instance of System.Collections.ArrayList object.

Here,System.Collections.ArrayList being a .NET class used for creating dynamic arrays(again no need to worry about Redim and Preserve)

After creating arraylist object we then use the Add method to add items to our array.

Sort() method is used to sort in ascending order while i haven’t found reverse() method flexible as sort.For reversing we need to sort first and reverse it again..2 steps!

Lets start with:

'================================================
'Author:QTP Lab:a touch of madness!
'Date:23/11/2009
'Description:This function sorts an array into ascending
'            and descending order using .Net class methods.
'Function:SortArray()
'=========================================================

Function SortArray()

Dim myObj,sBf
sBf=""
Set myObj=CreateObject("System.Collections.ArrayList")
myObj.Add("Ba")
myObj.Add("R")
myObj.Add("A")
myObj.Add("Bb")
myObj.Add("S")
myObj.Add("M")
myObj.Add("D")
myObj.Add("J")
myObj.Add("Bc")
myObj.sort()
'myObj.reverse()   'Disable this line if you want to sort in an ascending order.

For each sNames in myObj
sBf=sBf&sNames&"-->"
Next
msgbox sBf,0,"Ascending order"

Set myObj=Nothing

End Function

Output:


Checkproperty method in QTP:


Checkproperty method in QTP:
Check property in qtpAutomation tool itself does not find and report new bug(s) efficiently.It requires a skill of automation tester to let tool perform the operation in an efficient manner.We generally verify that application performs as expected;and if not,then report warning or info or error.Power of automation is unleashed only when we understand the thin line(hypothetical) that is between manual test and automation tool(s).I call this line as Auto-Manual bridge.I work out there.

Rolling back to topic again: There are different methods and properties available for checking/verifying.Exist,checkproperty, getROProperty etc.Let’s discuss Checkproperty method.We often come across a situation to verify the status of page load, test entered on the text box and similar scenarios.Checkproperty methods is very handy to solve the above problems easily.

Example:

Syntax:object.CheckProperty (PropertyName, PropertyValue, [TimeOut])

Example 1.Check the status of page.

>Browser("micclass:=Browser").Page("micclass:=Page").Object.CheckProperty ("status","done",3000)

Example 1.Verify the text Automationlab09 has been entered on the name textbox.

>Browser(“micclass:=Browser”).Page(“micclass:=Page”).WebEdit(“name of text box”).Set “Automationlab09”
sCheck=Browser(“micclass:=Browser”).Page(“micclass:=Page”).WebEdit(“Name”).CheckProperty (“value”, “Automationlab09”)

Here (in example 1), Quick test verifies whether the status on the status bar of browser is displayed as “done” or not. It waits till the timeout period ie. 3 seconds(in milliseconds),If it is unable to verify the status within 3 seconds then it’ll use the default time period specified in test settings.If verification is successful within time period it’ll return a boolean value TRUE and report test status as “PASSED” on test results else it’ll return boolean value FALSE and report the test status as “FAILED” on test results viewer.
This is an alternative way of using checkpoint in descriptive programming.

Send email with attachment from outlook using QTP:


Send email with attachment from outlook using QTP:

QTP send result in emailStakeholders are the persons to whom we need to report the coverage of our day to day testing activities.Members of management relies on the data..that’s it! They do not give damn interest on whether your scripts is running or not.I have seen most of my colleagues enjoying after the successful run of their scripts.Well, the mission of automation developer is not simply to run scripts or to debug.Automation developers are still the testers and the mission of automation and manual testers is same.Frequent manual intervention hassles our automation work.It’s wise to find out and reduce the human intervention on the running and ran scripts.After run session it’s wise to bundle up the result dumps, attach in mail and send to one/more of our stakeholders.Outlook provides a simpler way to achieve the same, before running the scripts you must make sure that outlook express has been configured on your machine.If outlook hasn’t been configured on your system then send mail functionality would not work.You could ask your tech-support guys to configure your outlook application to have a smooth ride.

Code:

'**********************************************
'Function: Sendmail_fromQTP
'Arguments:
                   'sMailto:Recipient email address

                   'sSubject:Mail subject

                   'sBody:Mail body text

                   'sAttachment: Attachment file path

'Description:Send mail using Outlook express
'Author:QTP Lab:--A touch of madness
'Website:http://automationlab09.wordpress.com
'Last modified:19/07/2010

'*********************************************

Function Sendmail_fromQTP(sMailto,sSubject,sBody,sAttachment)

set oMailobj=CreateObject("Outlook.Application")

set oSendmail=oMailobj.CreateItem(0)
      oSendmail.To=sMailto
      oSendmail.Subject=sSubject
      oSendmail.Body=sBody
      If (sAttachment <> "") Then
         oSendmail.Attachments.Add(sAttachment)
      Else
           Reporter.ReportEvent micInfo,"Sending mail:","Unable to send attachment,please verify your attachment file"

       End If 

       oSendmail.Send

set oSendmail=Nothing
set oMailobj=Nothing

End Function

'Usage:
 Sendmail_fromQTP "name@example.com","Mail from QTP","Your mail descrn goes here..","C:\test.txt"

I haven’t ran the code,please do let me know if you face any difficulties while working on above script.
Thank you!

Capture error image and publish it on QTP result:


Capture and report error image on QTP result:
Error handling,logging and reporting are prime challenges while developing automation framework.Our automated tests will only provide a fruitful result if it gives enough information about the test confidence (or coverage) of AUT;else Record and Run automation will only be a mission to see how software uses or manipulates software.
Image Capture:Before running the code,let’s assume the disk drive is empty enough to store our captured images.
and last but not the least,make sure that the path is relative.

Here “/” and “:” sign is replaced by “-” because file name doesnt accepts these characters.

Code:

Function CaptureImageonError()

Dim moment
Dim sMyfile

moment=Now() 'displays the current date and time
sMyfile= moment&".png"
Msgbox sMyfile
sMyfile = Replace(sMyfile,"/","-") 'removing special char / & :
sMyfile = Replace(sMyfile,":","-")
sMyfile= "C:\"&sMyfile 'Path where file would be saved

Desktop.CaptureBitmap sMyfile,true
End Function

Please refer image below to view the code to report image on result viewer(last line) as content editor doesnt allows me to type this line.

You must be wondering about &”lt” and &”gt” right?.Well,it’s just a workaround to fool QTP upto 9.5 version.Only < will do without &gt.
The difference between genius and stupidity is that genius has its limits.–Albert Einstein ;)

Output:

QTP image capture

For QTP 10+ users:
Syntax:
Reporter.ReportEvent EventStatus, ReportStepName, Details [, ImageFilePath]

Issues in identifying DIV with QTP:


Issues in identifying DIV with QTP:
Div stands for division and in case of HTML document,it defines a section in an document.
Nowadays developer prefer DIV over TABLE for design purpose.I have had heard that elements within DIV loads faster than within Table;i don’t know what is the exact difference and don’t want to discuss :) as it’s out of scope as of now.QTP has a set of methods and properties for Table under micclass WEBTABLE, testers often come across the scenario when they have to choose between two alternatives TABLE and CHAIR, oh! no! ;) CHAIR is not there,need to work on table without sitting on the chair?
Yes, if we have QTP we can do it too,that’s why i am against the saying “Pen is mightier than sword”, i believe “QTP is mightier than sword”.

Well,we need to fetch the “Class” or “Id” attribute in order to identify the particular DIV in HTML document object model and our mightiest code is as follows:

Code:

Function Identify_DIV()

Dim Obj

Set Obj= Description.Create

Obj("micclass").Value = "WebElement"  ' alternative

Obj("html tag").Value = "DIV"

Obj("class").Value = "header"

Browser("micclass:=browser").Page(Obj).Click

Wait(2)

'Set Obj =Nothing

End Function

Raw DIV Code:

Raw DIV in QTP

Follow

Get every new post delivered to your Inbox.