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.

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
nRowCount=DataTable.GlobalSheet.GetRowCount

'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 gmail.com
   Systemutil.Run "iexplore", "http://gmail.com"

   'Wait for the page to load
   Browser("title:=.*").Page("title:=.*").Sync

   'Get the current row User name and password and store it in variables
   DataTable.GlobalSheet.SetCurrentRow(i)
   sEmailid=DataTable("UserName",Global)
   sPassWord=Datatable("PassWord",dtGlobalSheet)

   '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
   Browser("title:=.*").Page("title:=.*").Sync

   wait(10)

   '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")
   Else
      msgbox("Login Unsuccessful")
   End If

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

Next

'Result
'## 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.

4 comments:

Please leave your comment here...