Categories
Uncategorized

Synchronization in UFT

We are already done with the synchronization in selenium, today we would discussing the same in UFT.Before starting with the synchronization we would recommend to use Exist,WaitProperty,Sync rather than using Wait.

1.wait
This is used when we want UFT to wait for the specified time, so that AUT completes its current operations.It is like pausing the script run for the given amount time(Same like Thread.sleep)
Syntax:- Wait (seconds)
Example:- wait(2)
Given script will pause for 2 seconds.
Note:- if we don’t pass any value  like wait()
it Will generate runtime error.

Wrong Number of Arguments Wait in UFT
Wait,generated Error for missing Time value

Using Wait is not considered as good coding practice, because it is like pausing the script independent of any condition and UFT would wait even if the process for which wait was applied have been completed.We can still use it if nothing from the below properties or methods works out , or we are sure that process will always takes a given amount of time.

2.waitproperty
Is it used to Wait until the the given object property achieves the specified value in the given timeout else it continues to the next step.
Syntax:-object.WaitProperty(PropertyName, PropertyValue, [TimeOut])
Note:- Timeout(milliseconds) is optional,incase it is not provided default synchronization timeout is taken(File->Settings->Run->Object synchronization timeout)
Return Type:- Boolean (True incase property value is achieved in the given Timeout)
Example:-

'To wait for 30 seconds for the the Home link to be loaded 
Set obj = Browser("CreationTime:=0").Page("Index:=0").Link("text:=HOME","html tag:=A")
If obj.WaitProperty("attribute/readyState", "complete", 3000) Then
obj.Click
EndIf


3.exist Property
It instructs UFT to wait for a specified object to appear. 
Syntax:-
Object.Exist(Timeout)
Return Type:-Returns a boolean value indicating whether or not an object currently exists
Note:- Timeout(seconds) is optional,incase it is not given it would take the default synchronization timeout (File->Settings->Run->Object synchronization timeout)
Example:-

'Code to wait for 30 seconds for the Link to exist
Set obj = Browser("CreationTime:=0").Page("Index:=0").Link("text:=HOME","html tag:=A")
If obj.Exist(30) Then
obj.Click
End If


4.sync Method(Only for Web AUT)
Waits for the browser to complete the current navigation.
Syntax:-
Object.Sync
Example:-

'Waits for the Page to load
Browser("CreationTime:=0").Page("Index:=0").Sync


How to modify Default Timeout values:-
Note:- Default ‘object’ sync time is 20 seconds and Browser ‘Navigation’ sync is 60 seconds
Sync:-
File > Settings > Web pane

Browser Navigation Timeout in UFT
Changing Browser Navigation Time 

Exist,WaitProperty:-
File->Settings->Run->Object synchronization timeout
We can always play with the default synchronization time that UFT takes for Exist,WaitProperty or by default before it throws error to the user.

Object Synchronization Timeout in UFT
Changing Object Sync in UFT

Learn UFT
Learn Selenium

Leave a Reply

Your email address will not be published. Required fields are marked *