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





0/5 (0 vote)
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 FunctionHope it helps. Happy scripting :)