Highlighted
Respected Contributor.
Respected Contributor.
818 views

Speed up If statements with several exist

Jump to solution

Hi everbody,

I have a webapplication that has 2 possible results. You never know which of the results you will recieve since I'm using random inputs. I'm stopping the time to see how long it takes for the application to show me the results. I check for the results like this:

If (object1.Exist) OR (object2.Exist)

But now the problem is that, if object2 comes up, UFT only checks for object2 if there is a timeout for object1.

Is there any way to speed this up? 

Thank you in advance!

0 Likes
1 Solution

Accepted Solutions
Highlighted
Honored Contributor.
Honored Contributor.

Will this work ...?

time1 = timer()
time2 = timer()
global_timeout = 60 ' seconds
Do 

    If (myObj1.exist(1) = True) Then
        print("Obj_1 appeared after : " & time2 - time1 & " seconds")
        Exit Do ' break if Obj_1 appeared
    End If
    If (myObj2.exist(1) = True) Then
        print("Obj_2 appeared after : " & time2 - time1 & " seconds")
        Exit Do ' break if Obj_2 appeared
    End If
    
    time2 = timer()
Loop while ((time2 - time1) <= global_timeout)
 

View solution in original post

7 Replies
Highlighted
Honored Contributor.
Honored Contributor.

Try using Exist with defined timeout. Like Exist(0). So, it will not wait for the default timeout, which is usually more.

so, if one of the objects exists, it will enter the loop and it will not wait for default timeout to check if second object exist. 

GoScriptLESS Create UFT Tests in seconds view demo and more details at scriptlessautomation.com

 

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

Unfortunatly this is no solution for me.

I want to check for both outcomes simultaneously within the default timeout window.

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Do you wish to time it, until one or more items are shown?

Do you need only to know when each object appeared?

 

You can override via code, the default timeouts, however the original questioni s not very clear to me, so I am not sure that my suggestion is an option for you...

 

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

Only 1 object can show up on screen it is not possible that both of them will show up. 

I want to stop the time that it takes until one of them is displayed.

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Will this work ...?

time1 = timer()
time2 = timer()
global_timeout = 60 ' seconds
Do 

    If (myObj1.exist(1) = True) Then
        print("Obj_1 appeared after : " & time2 - time1 & " seconds")
        Exit Do ' break if Obj_1 appeared
    End If
    If (myObj2.exist(1) = True) Then
        print("Obj_2 appeared after : " & time2 - time1 & " seconds")
        Exit Do ' break if Obj_2 appeared
    End If
    
    time2 = timer()
Loop while ((time2 - time1) <= global_timeout)
 

View solution in original post

Highlighted
Honored Contributor.
Honored Contributor.

That should work.  One little change I would suggest is to change exist(1) to exist(0), so that we can eliminate wait for 1 sec. Loop is handling the over all wait time, we dont have to wait for each object.

Highlighted
Respected Contributor.
Respected Contributor.

Tested things out with exist(0) and it works perfectly!

Thank you guys!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.