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()
browserURL=Browser("title:=http.*://.*Login.aspx.*").Page("url:=http.*://.*Login.aspx.*").GetROProperty("URL")
Browser("title:=http.*Login.aspx.*").Page("url:=http.*Login.aspx.*").Image("File name:=login_btn.png").Click
wait 10
If instr(browserURL, "Dashboard") > 0 Then
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
End If
End Function
Hope it helps. Happy scripting :)