Saturday, June 7, 2008

Defference between Import and ImportSheet

Import method will imports the specified Excel file to the run time datatable.
Ex: Datatable.Import ("C:\sample.xls")

ImportSheet method will imports a specified sheet of a specified file to a specified sheet in the datatable.
Ex: Datatable.ImportSheet "c:\sample.xls", SourceSheetName(or Number), DestinationSheetName(or Number)


If excel file has 7 sheets, if we use import method, then all the 7 Sheets are imported into the runtime datatabe?
The Answer is No. Only the first 2 sheets will be imported into the runtime datatable.
Not all the sheets.
why because, By default datatable will have 2 sheets (Global/Local)
If you add an action in the QTP then only, a new sheet will be added in to the datatable.

How to compare the list box items with another

Here i am giving the script to compare the list box items with another -
To run this script you have to add all the objects into the object repository
(Find the link in this blog "how to add objects into the object repository")

Window("Flight Reservation").activate
SeltItem = window("Flight Reservation").winComboBox("Fly From:").GerROProperty("text")
msgbox SelItem
'It displays the selected item in the list
ListItem = Window("Flight Reservation").WinComboBox("Fly To:").GetContent
msgbox ListItem
'It displays all the items in the list box
Itemcount = window("Flight Reservation").WinComboBox("Fly To:").GerItemsCount
msgbox Itemcount
'It displays no of items in the list box
For i=0 to Itemcount-1
a=window("Flight Reservation").wincombobox("Flt To:").GetItem(i)
If SelItem=a Then
msgbox "Items Are Matching"
else
msgbox "Items Are Not Matching"
End If
Next

Script for Orkut Login

url = "www.orkut.com"
Systemutil.Run "IExplore", url
'It will open a Browser with any website address
Browser("name:=orkut - login").WebEdit("name:=Email").set "rajaputra"
Browser("name:=orkut - login").WebEdit("name:= Passwd").setSecure "47525d8be4926ea2f6e96b9a3f7472b6ae38"
Browser("name:=orkut - login").WebButton("name:=Sigh in").Click
Browser("name:=orkut - login").Link("name:=Logout").Click
Browser("name:=orkut - login").Close

Friday, June 6, 2008

Import and Export Methods

Here i am giving the script for Importing data from data table and exporting the data table into Excel File.

SystemUtil.Run "C:\ProgramFiles\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"

Dialog("text:= Login").Activate
Dialog("text: = Login").WinEdit("Attached text:=Agent Name").set "rajaputra"
Dialog("text: = Login").WinEdit("Attached text:=Password").set "mercury"
Dialog("text:=Login").WinButton("text:=OK").Click
Window("text:=Flight Reservation").Activate
datatable.importSheet "C:\example.xls",1,1
rowcount=datatable.GetRowCount
For i=1 to rowcount
Window("text:=Flight Reservation").WinButton("window id:=5").Click
Dialog("text:=Open Order").Activate
Dialog("text:=Open Order").WinCheckBox("text:=&Order No.").set "ON"
datatable.SetCurrentRow(i)
n=datatable(1,1)
Dialog("text:=Open Order").WinEdit("window id:=1016").set n
Dialog("text:=Open Order").WinButton("text:=OK").Click
If(window("text:=Flight Reservation").Dialog("text:=Open Order").Dialog("text:=Flight Reservation").exist)then
window("text:=Flight Reservation").Dialog("text:=Open Order").WinButton("text:=Cancel").Click
datatable(2,1)="Not Exist"
Else
datatable(2,1)="Exist"
End If
Next
Datatable.Export ("C:\flights.xls")
window("text:=Flight Reservation").Close


Before running this script, in "example.xls" you have to put two columns.
one is OrderNo and one is Result.
In OrderNo you can enter any valid or invalid OrderNo's and Result you can leave as it is.
We will out put the data into Results.

What is Input Parameters and OutPut Parameters

Input parameter allows you to run a test using different set of data input values.
When you use a datatable parameter, you must instruct QuickTest on where the input data will come from.

An output parameter is a value which comes back from the application under test. When you run the test QuickTest retrieves the current value of the property and enters it in the run-time datatable as an output value.

You can subsequently use this output value as a input value in your test. We call this data correlation. This enables you to use data retrieved during other parts of test.

How to run the batch file through Script

I have taken 3 tests as a example for doing batch run. They are

1. Display -It will display a message in a word doc.
2. DisplayDate - It will display a date and time in a Notepad
3. Multiplication - It will display a mathematical table in Notepad

I converted them in respective funcitons and saved in notepad as a .vbs file.
(in C:\VBLibraryFiles\)
And i wrote a VBS Finction that is called above 3 functions and saved as a callAll.vbs
(in C:\VBLibraryFiles\)
Before running the test I loaded all files into resource tab

callAll() 'Here i am just calling callAll function which is defined in callAll.vbs file

**********************

Display.vbs -

public funciton display()

set WordObj = CreateObject("Word.Application")
WordObj.visible = true
Set wordDoc = WordObj.Documents.Add
WordDoc.Range.InsertBefore "Hi Good Morning"
WordDoc.SaveAs "C:\Greetings.doc"
WordDoc.quit
Set wordObj = Nothing

End Function

***********************

DisplayDate.Vbs -

Public Function displayDate()

Set fso = createObject("Scripting.filesystemObject")
Set fptr = fso.createTextfile("C:\Sample.txt")
a = FormatDateTime(Date,1)
fptr.writeLine a

End Function

*******************************

Multiplication.Vbs -

Public Function multiplication()

Set obj = createObject("Scripting.filesystemObject")
Set of = obj.createTextFile("C:\mat.txt")
For i=1 to 10
x=5*1
of.writeLine "5 * "&i&" = "&x
Next

End Function

*****************************

CallAll.Vbs -

Public Function callAll()

display()
msgbox "Test 1 is pass"
displayDate()
msgbox "Test 2 is pass"
multiplication()
msgbox "Test 3 is pass"

End Function

How to copy the file from one location to another location

dim filesys
Set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("C:\sourcefolder\anyfile.ext") then
filesys.CopyFile "C:\sourcefolder\anyfile.ext", C:\destinationfolder\"
End If

How to get the Count of each file in a particual folder

Set fso = CreateObject("Scripting.FileSystemObject")
Set fold = fso.getFolder("D:\testingfiles")
Set fc = fold.files

word=0
xls=0
txt=0

datatable.getSheet(1).addParameter "Word",""
datatable.getSheet(1).addParameter "Excel",""
datatable.getSheet(1).addParameter "text",""
datatable.getSheet(1).addParameter "Total Files",""

For each f in fold.files

if lcase(right(f.name,4)) = ".doc" then
word=word+1
end if

if lcase(right(f.name,4))= ".xls" then
xls=xls+1
end if

if lcase(right(f.name,4))= ".txt" then
txt=txt+1
end if
next

datatable(1,1)=word
datatable(2,1)=xls
datatable(3,1)=txt
datatable(4,1)=fc.count

'Run this script and see the runtime datatable

Select RadioButton through Datatable

Browser("micClass:=Browser").Page("micClass:=Page").WebRadioGroup("name:=servClass").Select
Datatable("FlightClass, dtGlobalSheet)

'Here FlightClass is (Coach,Business, First) in the datatable.

How to Run and Close the application during Run time

We can Invoke the application during run session using

SystemUtil.Run "NameOfFile"

Systemutil.Run Statement enables you to open or run any application from a given location.
Similarly, you can use SystemUtil to close the application like this:

SystemUtil.CloseProcessByName "explorer.exe"

Working With Excell

Here I am discussing
How to create a Excel Sheet
Storing the data into Excel Sheet
Reading the data from Excel Sheet

Creation of Excel Sheet -

Set Excel=CreateObject("Excel.Activation")
Set ExcelSheet=CreateObject("Excel.sheet")
ExcelSheet.Application.visible=true

Storing the data into Excel Sheet -

Excel.ActiveSheet.Cells(1,1).Value="UserName"
Excel.ActiveSheet.Cells(1,2).Value="Password"
Excel.ActiveSheet.Cells(2,1).Value="arunsingh"
Excel.ActiveSheet.Cells(2,2).Value="rajaputra"
ExcelSheet.SaveAs "C:\text.xls"
datatable.Import "C:\text.xls" 'Importing excel sheet into datatable

Reading the data from Excel Sheet -

msgbox "UserName is="+Excel.ActiveSheet.Cells(2,1)
msgbox "Password is="+Excel.AcitveSheet.Cells(2,2)

How to Capture the Screen Shot

By using the below script we can capture the screen shot at run time -

Browser("BrowserName").Page("PageName").captureBitmap "c:\test\ScreeShot1.bmp"

Below example will help you to get familiar with this-
'Prerequisite: Open the FlightReservation Login screen
'Then Run this Script

Set Dlg=Dialog("text:=Login")
set Wnd=Window("text:=Flight Reseravation")
Set oDlg=wnd.Dialog("text:=Open Order")

Dlg.WinEdit("attached text:=Agent Name").set "rajaputra"
Dlg.WinEdit("attached text:=Password").setSecure "mercury"
Dlg.WinButton("text:=OK").Click

wait (7)

wnd.Activate
wnd.WinButton("window id:=5").Click
oDlg.WinCheckBox("text:=&Order No.").Set "ON"
oDlg.WinEdit("window id:=1016").set "100"
oDlg.WinButton("text:=OK").Click

if(oDlg.Dialog("text:=Flight Reservations").Exist) then
oDlg.Dialog("text:=Flight Reservations").CaptureBitmap "C:\ScreenShot.bmp"
oDlg.Dialog("text:=Flight Reservations").WinButton("text:=OK").Click
oDlg.WinButton("text:=Cancel").Click
End If

wnd.Close

Wednesday, June 4, 2008

What is Datatable

Data table assists you in parameterizing the test.
There are two type of Data tables are available in QTP.
1. Design time data table 2. Runtime Data table.

Design time Data table -

There are two type of data sheets available, they are 1. Global Data Sheet 2.Local Data Sheet
The Global Data Sheet contains the data that replaces parameters in each iteration of test.
Each time you add a new action to the test, a new action sheet (Local Sheet) added to the data table. It contained data, replaces parameter in only one iteration of the test.

Run time Data table -

During a run session, Quick test creates a runtime data table.
When the run session ends, the runtime data table closes, and the data table pane again displays the stored design time data table.
The final data from the runtime data table is displayed in the runtime data table in the test results window.

Mandatory - Assitive - Ordinal Identifier properties

Quick test identify the objects by learning the default property values is called mandatory properties.
Ex - attached text, native class, alt, html tag, image type.

If the mandatory properties are not sufficient to create a unique object description then Quick test uses Assistive properties of the object to identify uniquely.
Ex - Id

If the mandatory and assistive properties are not sufficient to create a unique object description then Quick test uses Ordinal identifier to create a unique description of the object.
Ex - index, location, creation time.

How to load the Object Repository

To load the object repository at runtime -
Write following script...

Set app=CreateObject("QuickTest.application")
app.test.settings.resources.ObjectRepositoryPath="Path of the Object Repository"


To load manually -

Goto Test-Settings-resources-select shared for Object Repository Type-Browse the required Object Repository.

What is Object Repository

Object Repository is a place where all recorded or added objects are stored.
When you record the application, recorded objects are stored in the Object Repository, in order to use them later.
Object Repository mainly identifies how it will recognize an object at the time of replay.
Object Repository displays a tree of all objects in the current component or in the current action or entire test (depending on the object repository mode you selected)
We can view or modify the test object description of any test in the repository or we can add new objects to the repository.
There are two types of Object Repositories : Per Action and Shared Action

When we are working in Object Repository, Per Action mode, Quick test creates a new object repository for each action.
When we are working in Object Repository, Shared Action mode, Quick test adds new objects to the object repository.
If we record operations on a object that already exists in the Shared Object Repository, Quick test uses the existing information, and does not add the object to the Object Repository.

How QTP Recognize the Objects in AUT

When we record the application, QTP interact with an object and stores Test object properties in its Object Repository.
When the test runs, QTP maps the Test Object properties with the Runtime Object properties.
If it successfully maps the runtime properties, then test passes.
If not, test fails.

Test Object Properties - are properties of an object in the Object Repository
Runtime Object Properties - are properties of an object in the application.

Runtime Object is the actual object to which a Test Object can be mapped.
It is the actual object present in your AUT.

Example -

Open a Notepad and add objects in Object Repository
Then write script in QTP...
Msgbox window("Notepad").GetTOProperty("height")
'It gives you empty message. Because you didn't add height in Object Repository.
'Now try this
Msgbox window("Notepad").GetROProperty("height")
'You will get the height of the notepad window.

For Test Object, you have to add the property then only it will show in the test object properties list.
But for Runtime Object, always all properties are available.

We can use SetTOProperty method to change the properties of the test object, But we cannot change the properties of the Runtime Object.

Tuesday, June 3, 2008

Smart Identification

When Quick test uses the recorded description, to identify the object, it searches for the object that matches every property value in description.
If Quick test unable to find any object that matches the recorded object description, or if it finds more than one object that fits description and uses the smart identification mechanism to try to identify the objects.

A smart identification mechanism can help Quick test to identify an object, even if recorded description fails due to changes in property values.
In Smart Identification we have to mention the set of base filter and optional filter properties to identify the object in the application.
Smart Identification is required only if mandatory, assistive properties are failed to recognize the object.


Base Filter - Fundamental properties of particular object, those whose values cannot be changed without changing the essence of original object.
Optional Filter - Other properties can help to identify objects of a particular class as they are unlikely to change on a regular basis but which can be ignored if they are no longer applicable.

Library Files

Library files are containing normal VB Script code.
We can load library files by using 2 ways -

1. Choose Test-Settings-Resources tab-Click on + button - browse and select library file-click OK
2. Use Executefile function to load library files at run time.

When we associate a library file with the test, then all functions with in the library are available to the actions presents in the test.
But when we use executefile function to load a library file, then the functions with in the library file are restricted to a specific action.


Ex: ExecuteFile "FilePath"

Sample Script:

execute file "C:\sample.vbs"
x=10
y=5
result=SumofTwoNumbers(x,y)
msgbox (result)

Code in Sample.vbs -

Public Function SumOfTwoNumbers(a,b)
Dim sum
sum=a+b
SumOfTwoNumbers=sum
End Function

Error Handling

Error handling enables us to convert system generated error messages to user defined messages.

"On Error Resume Next" should be used when you know if an error is expected and don't want to raise it. You may want to do different actions depending upon the error that occurred.

Use err.number and err.description to get more details about the error.

How to handle the exceptions

By using Recovery Scenario Manager, we can handle the exceptions occurred while running the test.

Recovery is a concept like exception handling in a programming language, which can be applied when an unexpected failure occurs.


When TO Use:
We should use Recovery Scenario only for unpredictable events, or events that cannot synchronize with a specific step in our test.

4 Exceptions in QTP:
1. Popup Window - A popup window appears in an open application during a test run.
2. Object State - Property of the object changes its state or value.
3. Run Error - A step in the test does not run successfully
4. Application Crash - An open application fails during a test run.

3 Types of Recovery Scenarios:
1. Triggered Events - Trigger is nothing but the cause for initiating the recovery scenario.
2. Recovery Steps - It defines what needs to be done, when recovery scenario has been triggered.
3. Post Recovery Test Run - It defines what need to be done after the recovery action has been taken. It could be repeat the step or move to next step etc..

Monday, June 2, 2008

About Parameterization

To data drive we have to parameterize.
Through parameterization only we can drive a transaction with different set of data.

Parameterization:
When we test the application, we may want to check how it performs the same operations with multiple set of data.
In parameterization, data can be typed or import from database, spread sheet or text files.

4 Types of parameters:
1. Test, Action parameter - enable you to use values passed from the test or values from other actions in our test.
2. Data table parameter - enable you to create a data driven test, that runs several times using the data you supply. In each iteration quick test uses a different value from the datatable.
3. Environment Variable parameter - enable you to use values from other sources during run session.
4. Random Number Parameter - enable you to insert random numbers as values in our test.
Ex: RandomNumber(0,20)

About Me

My photo
Hi all,I am Arun Singh Rajaputra. I am working as a Project Lead in a reputed organization in Hyderabad, AP, India. I have little bit knowledge on Quick Test Professional and like to share my knowledge to all through this blog.

Subscribe to get updates on this blog

Enter your email address:

NOTE

Some of the posts posted in this blog are collected and most of them have been prepared by me. If any one have objections regarding any copied posts. Please mail me so that I can take a necessary action on that post.