Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

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

0.00/5 (No votes)
30 Sep 2011 1  
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here