Thursday, March 31, 2011

QTP script to login to Gmail using different sets of logins from datatable

In the following example there is no need of recording any scripts. Just copy paste the below script and it should work provided you meet the prerequisites.

1) Ensure that you set the run settings to "Run one iteration only"
2) Create the datatable (Global sheet) parameters => Rename Columns A & B as UserName and PassWord respectively (as shown below)
3) Update the test data (Different sets of user name password combinations on the global sheet (as shown below).

QTP Data Table Global Sheet
QTP Data table (global sheet), click on the image to enlarge

' Program to login to Gmail using different set of logins from a datatable
' Table Structure (parameters): UserName, PassWord

'Retrieve the number of rows in the table

'Close any existing IE browser windows
systemutil.CloseProcessByName "iexplore.exe"

'For every User name Password combination
For i = 1 to nRowCount

   'Open a new IE browser and navigate to
   Systemutil.Run "iexplore", ""

   'Wait for the page to load

   'Get the current row User name and password and store it in variables

   'Update the user name and password on the page and sign in
   Browser("title:=.*").Page("title:=.*").WebEdit("name:=Email").Set sEmailid
   Browser("title:=.*").Page("title:=.*").WebEdit("name:=Passwd").Set sPassWord
   Browser("title:=.*").Page("title:=.*").WebButton("name:=Sign in").Click


   'Check if the left 13 charecters of the browser title is "Gmail - Inbox"
   If left(browser("title:=.*").Page("title:=.*").getROProperty("title"),13) ="Gmail - Inbox"Then
      msgbox("Signed in Successfully")
      msgbox("Login Unsuccessful")
   End If

   'Close the IE browser
   systemutil.CloseProcessByName "iexplore.exe"


'## Message box prompting whether the login was successful or not for all the login id and password combination

Check out more such QTP scripts here.


Please leave your comment here...