Click here to Skip to main content
15,883,883 members
Articles / Programming Languages / VBScript
Tip/Trick

Useful function to get and compare runtime URLs using QTP - vbs

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
30 Sep 2011CPOL 10.9K  
This article helps in getting the runtime URL and compare with user defined, 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 handling, i.e., if your application is deployed on multiple servers/environments every time you ran a 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, set the login credentials, i.e., username and password and make a function call.

Public Function FunctionName() //Function Declaration

browserURL=Browser("title:=http.*://.*Login.aspx.*").Page("url:=http.*://.*Login.aspx.*").GetROProperty("URL")  //Gets the runtime URL and assign the value in the variable

Browser("title:=http.*Login.aspx.*").Page("url:=http.*Login.aspx.*").Image("File name:=login_btn.png").Click //Click on the Login button

wait 10

If instr(browserURL, "Dashboard") > 0 Then // Conditional statement that checks the variable value with the user defined value  (Use first page name)
Reporter.ReportEvent micPass, "Login success", "Correct credentials. Authenticated successfully"
				
Elseif(Browser("title:=http.*Login.aspx.*").Exist(05)) then 
Reporter.ReportEvent micFail, "Invalid / Wrong credentials", "Incorrect credentials. Authentication Failed"

Browser("title:=http.*://.*Login.aspx.*").close
ExitTest //Exits the test
End If

End Function


Hope it helps. Happy scripting :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Tester / Quality Assurance
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --