Monday 28 November 2011

Descriptive programming example on login page

this is me, vinod rajput. i found number of Tester in QTP have faced the Problems regarding Login page functionlaity for
. for valid login
. for invalid login etc. for different test cases that you made for your Sciprt in Test.
Now i have solution for those who faced this probs. PlayBack this script in ur machine as follows:

 ’ *******Checking the Login page functionality*******
Function  Login(UserName,Password)
‘**** Using the Desciptive programming to set username, Password & click on the Submit Button ****
 Browser(“Title:=Login”).Page(“Title:=Login”).WebEdit(“Name:=txtLoginId”).Set UserName
 Browser(“Title:=Login”).Page(“Title:=Login”).WebEdit(“Name:=txtPassword”).Set Password
 Browser(“Title:=Login”).Page(“Title:=Login”).WebButton(“Name:=Submit”).Click
‘**** Incase, we entered the Invalid usernam/Password ****
 page_1 = Browser(“Name:=Login Failure!!!”,”Index:=0″).Exist

 if page_1 then  ‘ ***if Username/ Password is/are Invalid, page_1 becomes true ***
  Browser(“Title:=Login Failure!!!”).Page(“Title:=Login Failure!!!”).Link(“Name:=Click here”).Click
  Reporter.ReportEvent “1″,”Invalid username: “&UserName,”Login Failed due to Invalid Username: “&UserName
  ExitTest
 End If
‘*** Incase,  click on Submit without entering username/ password ***
 page_2 = Browser(“Title:=Login”).Exist
 if page_2 then
  Reporter.ReportEvent 1,”User Name cannot be left blank!!!”, “Please Enter the UserName : User Name cannot be left blank!!!”
  ExitTest
 end if
‘*** For valid username/ Password  ***
 if not(page_1 And page_2) then
  Reporter.ReportEvent 0, “Login Successful for User ID:”& Username, “Login successful, Test:Passed”
 end if
End Function

No comments:

Post a Comment