Checking Object Existence - QTP

Consider the following Login example:

'Set the user name and password
Browser().Page().WebEdit("uid").Set "Username"
Browser().Page().WebEdit("password").Set "password"
'Click on the login button
Browser().Page().WebButton("login").Click
'Check if login failed text exist
If Browser().Page().WebElement("innerText:= Login failed").Exist(5) Then
Report.ReportEventmicFail, "Login", "Login failed"
Else
Report.ReportEventmicPass, "Login", "Login Successful"
End if

Using the above code, users who specify a good login and password, which is normally the case, these users will waste 5 seconds waiting for a Login failure message that will not occur. In this example, a "Logout" link appears when the login is successful, so if we test for both conditions we can proceed as soon as either occurs:

'Set the username and pasword>
Browser().Page().WebEdit("uid").Set "Username"
Browser().Page().WebEdit("password").Set "password"
'Click on login button
Browser().Page().WebButton("login").Click
'Check the existence of both objects
bLoginPass = Browser().Page().Link("text; "Logout").Exist(0)
bLoginFail = Browser().Page().WebElement("innerText:=Loginfailed").Exist(0)
i = 0
'Wait up to 5 seconds for a success or failure indication
While (Not bLoginPass or Not bLoginFail) and i < 5 Wait 1 i = i + 1
bLoginPass = Browser().Page().Link("text" "Logout").Exist(0) bLoginFail = Browser().Page().
WebElement("innerText:=Login failed").Exist(0)
Wend
'Check if login fialedIf bLoginFail Then

Report.ReportEventmicFail, "Login", "Login failed"
'Check if login passed
Elself bLoginPass Then
Report.ReportEventmicPass, "Login", "Login Else
Report.ReportEventmicFail, "Login", "Failed to determine login status"
End if

above code might seem lengthy, but putting the code in a function and re-using it will reduce the time wasted during execution.

Browser Vs Page Sync

There is no documented difference between Sync on browser and a Page. Though these two seem to be different on what they wait for. Page sync will wait for the page to load which will work in cases where there are no frames inside the page. While a Browser Sync will wait for the page to load and also for all the frames inside the web page.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

QTP Topics