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

One thought on “Simple Parametrization in QTP

  1. Probably this is a much simpler way for your explanation….

    Id = DataTable.value(”EmailID “, dtGlobalSheet)

    Pwd= DataTable.value(”Password“, dtGlobalSheet)

    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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s