Tuesday, March 2, 2010

Automation Frameworks

The Free Application available in the following link:(Can be used for practice)

Automation Framework:
This is used to execute automation script smoothly. this smooth execution can be achieved by avoiding manual intervene and by speeding up the automation test script.

Why we say smoothly execution of test script?
Ans: If any failure occurs when performing an operation. then QTP stops the execution.
Instead of stopping the execution. validate the script. if the failure occurs then skip the code and continue or avoid that failure. To avoid this, we should use automation frame work.
Here we go for functions to achieve this.

*Before we start learning AF, We need to know functions.
Go through the following example: To activate the calculator using function

1st Type:Store the object in a variable and pass the variable in function

'Object can be passed in a function
Set QTPObject=Window("Calculator")
Call ActivateDialog(QTPObject)
'Create a function to activate calculator
Function ActivateDialog(QTPObject)
QTPObject.Activate
End Function

2nd Type: Calling the function directly passing the object

Call ActivateDialog(Window("Calculator"))
'Create a function to activate calculator
Function ActivateDialog(QTPObject)
QTPObject.Activate
End Function

Ex(1)-Consider the example of the actiTime Login age
Following is example to validate the LoginNow button exist and enabled:
Code:(add the object to Object Repository)
IsExists=Browser("actiTIME - Login").Page("actiTIME - Login").WebButton("Login now").Exist(2)
IsDisabled=Browser("actiTIME - Login").Page("actiTIME - Login").WebButton("Login now").GetROProperty("disabled")

If IsExists Then
If IsDisabled Then
sMSG="The LoginNow button exists but disabled"
reporter.ReportEvent micFail,"Validation LoginNow",sMSG

else
sMSG="The LoginNow button exists and enabled"
reporter.ReportEvent micPass,"Validation LoginNow",sMSG
End If
else
sMSG="The LoginNow button does not exists"
reporter.ReportEvent micFail,"Validation LoginNow",sMSG
End If

Ex(2)-Above example Ex(1) can be used as a function.
'QTPobject can be any object of this page and should be there in object repository
'following is the example of login now button passed as QTPobject
set QTPobject=Browser("actiTIME - Login").Page("actiTIME - Login").WebButton("Login now")
'The object is set above which is being passed in a function
call ValidateExistsAndEnabled(QTPobject)
'The function is called above
Function ValidateExistsAndEnabled(QTPobject)
sObjectName = QTPobject.Tostring 'Tostring will give the name of the object passed
IsExists=QTPobject.Exist(2)
IsDisabled=QTPobject.GetROProperty("disabled")
If IsExists Then
If IsDisabled Then
sMSG=sObjectName&"exists but disabled"
'Tostring will help to display message dynamically without hard coading
reporter.ReportEvent micFail,"Validation LoginNow",sMSG

else
sMSG=sObjectName&" exists and enabled"
reporter.ReportEvent micPass,"Validation LoginNow",sMSG
End If
else
sMSG=sObjectName&"does not exists"
reporter.ReportEvent micFail,"Validation LoginNow",sMSG
End If

End Function

Ex(3)-Validating whether the object exists and enabled, Click if exists and enabled
'Continuing from the above example
'Pass the object like button as QTPobject and click it
set QTPobject=Browser("actiTIME - Open Tasks").Page("actiTIME - Open Tasks").WebButton("Add New Tasks")
bStatus=ValidateExistsAndEnabled(QTPobject)
if bStatus
QTPobject.click 'Click if exists and enabled
Function ValidateExistsAndEnabled(QTPobject)
sObjectName = QTPobject.Tostring
IsExists=QTPobject.Exist(2)
IsDisabled=QTPobject.GetROProperty("disabled")
If IsExists Then
If IsDisabled Then
sMSG=sObjectName&"exists but disabled"
reporter.ReportEvent micFail,"Validation LoginNow",sMSG

else
sMSG=sObjectName&" exists and enabled"
reporter.ReportEvent micPass,"Validation LoginNow",sMSG
End If
else
sMSG=sObjectName&"does not exists"
reporter.ReportEvent micFail,"Validation LoginNow",sMSG
End If

End Function



Sunday, February 28, 2010

Descriptive Programming

Descriptive Programming: This is to write and run a QTP script without adding objects in object repository

Ex(1): Write a DP script to log into Flight reservation application
Note: Flight reservation application comes with QTP default

Dialog("text:=Login").Activate
Dialog("text:=Login").WinEdit("Attached text:=Agent Name:").Set"aaaaa"
Dialog("text:=Login").WinEdit("Attached text:=Password:").Set"mercury"
Dialog("text:=Login").Winbutton("text:=ok").Click

Explaination:
Consider the above example,
The objects are identified with the properties and values in QTP(By physical description)
In Dialog("text:=Login"), text is a property and Login is a value. same way for WinEdit("Attached text:=Agent Name:"), Attached text is a property and Agent Name is a value