Pages

QTP-Function Library Example




'Global Variables Function Library
Public StrUrl,StrUName,StrPword

StrUrl="http://localhost:8080/mtours"
StrUName="User1003"
StrPword="mindq"
Function Library
Function LaunchApp(Url)
Systemutil.Run Url
If Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Exist(10) Then
Reporter.ReportEvent micPass ,"Launch App Check","Application Launched Successfully"
LaunchApp="Pass"
Else
Reporter.ReportEvent micFail ,"Launch App Check","Application not launched successfully for valid Url"
LaunchApp="Fail"
End If
End Function
Function NewUserReg(UName,Pword)
Dim ActMsg,ExpMsg
ExpMsg=UName
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Register").Click
If Browser("Welcome: Mercury Tours").Page("Register: Mercury Tours").Exist(10) Then
Reporter.ReportEvent micPass ,"Register Link Check","Application displyaed New User Registration Page"
Browser("Welcome: Mercury Tours").Page("Register: Mercury Tours").WebEdit("userName").Set UName
Browser("Welcome: Mercury Tours").Page("Register: Mercury Tours").WebEdit("password").Set Pword
Browser("Welcome: Mercury Tours").Page("Register: Mercury Tours").WebEdit("confirmPassword").Set Pword
Browser("Welcome: Mercury Tours").Page("Register: Mercury Tours").Image("register").Click
ActMsg=Browser("Welcome: Mercury Tours").Page("Register: Mercury Tours_2").WebElement("Note: Your user name is").GetROProperty("innertext")
ActMsg=mid(ActMsg,25,Len(UName))
If ExpMsg=ActMsg Then
Reporter.ReportEvent micPass ,"New User Registration Check","New User Registered Successfully"
NewUserReg="Pass"
Else
Reporter.ReportEvent micFail ,"New User Registration Check","New User Registration failed"
NewUserReg="Fail"
End If
Else
Reporter.ReportEvent micFail ,"Register Link Check","Application not displayed New User Registration Page"
End If
End Function
Function Login(Uname,Pword)
Browser("Welcome: Mercury Tours").Page("Register: Mercury Tours_2").Link("sign-in").Click
Browser("Welcome: Mercury Tours").Page("Sign-on: Mercury Tours").WebEdit("userName").Set UName
Browser("Welcome: Mercury Tours").Page("Sign-on: Mercury Tours").WebEdit("password").Set Pword
Browser("Welcome: Mercury Tours").Page("Sign-on: Mercury Tours").Image("Login").Click
If Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").Exist(10) Then
Reporter.ReportEvent micPass ,"New User Login Check","New User Login is successful"
Login="Pass"
Else
Reporter.ReportEvent micFail ,"New User Login Check","New User Login Failed"
Login="Fail"
End If
End Function
Function Logout()
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").Image("sign-off").Click
If browser("Welcome: Mercury Tours").Page("Sign-on: Mercury Tours").Exist Then
Reporter.ReportEvent micPass ,"LogOut Check","System redirected to Login Page"
Logout="Pass"
Else
Reporter.ReportEvent micFail ,"Logout Check","System not displayed Login Page"
Logout="Fail"
End If
End Function
Function CloseBrowser()
Browser("Welcome: Mercury Tours").Close
If Browser("Welcome: Mercury Tours").Exist(1) Then
Reporter.ReportEvent micFail ,"Close App Check","Application not Closed Successfully"
CloseBrowser="Fail"
Else
Reporter.ReportEvent micPass ,"Close App Check","Application Closed Successfully"
CloseBrowser="Pass"
End If
End Function
'New User Registration Test
'Project Name : Mercury Tours
'Module Name : Customer
'Script Desc : This script validates new user registration & Login
'Author : xxxxxxxxxxxxxxxxxxxxx
'Created Date : xx/xx/xxxx
Option Explicit
Call LaunchApp(StrUrl)
Call NewUserReg(StrUName,StrPword)
Call Login(StrUName,StrPword)
Call Logout()
Call CloseBrowser()

0 comments:

Post a Comment