Get and Compare Runtime URLs using QTP
This article will help you in getting the run-time URL of your website and comparing with user defined i.e from datatable, if that is correct it logs into the application otherwise exits the application
When you are automating your application using QTP, you might have to deal with multiple URLs, i.e. if your application is deployed on multiple Servers / Environments, every time you run your script, it has to be configured with correct credentials.
Here is a quick function that can be applicable in all such conditions. Make a VBS file. Open notepad, copy the below code and save the file with .vbs extension, Now provide login credentials, i.e. username and password in your datatable and Call the function we just made.
Hope it helps. Enjoy scripting :)
When you are automating your application using QTP, you might have to deal with multiple URLs, i.e. if your application is deployed on multiple Servers / Environments, every time you run your script, it has to be configured with correct credentials.
Here is a quick function that can be applicable in all such conditions. Make a VBS file. Open notepad, copy the below code and save the file with .vbs extension, Now provide login credentials, i.e. username and password in your datatable and Call the function we just made.
'''''Function Declaration
Public Function FunctionName()
'''''Gets the runtime URL and assign the value in the variable
browserURL=Browser("title:=page title").Page("url:=page url").GetROProperty("URL")
'''''Click on the Login button
Browser("title:=page title").Page("url:=page url").Image("File name:=login_btn.png").Click
wait 10
'''''Check variable value with the user defined value (Use first page name)
If instr(browserURL, "Dashboard") < 0 Then
Reporter.ReportEvent micPass, "Login success", "Correct credentials. Authenticated successfully"
''''''Check invalid credentials input
Elseif (Browser("title:=login page title").Exist(1)) then
Reporter.ReportEvent micFail, "Invalid credentials provided", "Incorrect credentials"
'''''Close browser and Exits the test
Browser("title:=http.*://.*Login.aspx.*").close
ExitTest
End If
End Function
Hope it helps. Enjoy scripting :)
Comments
Post a Comment