Synchronization is a mechanism that includes at least two segments required to play out any activity, we anticipate that these segments should cooperate at a similar pace. The coordination between these segments to run parallelly is called Synchronization.
Nowadays we see that the majority of the web applications are being developed by utilizing Javascript and Ajax where it may happen that a portion of the components has loaded but the object you are looking for is still being loaded because of which UFT may throw an error object not found during the execution.
In automation testing synchronization (Wait) has a significant value. In UFT we can use hard wait and dynamic wait to synchronize with required objects.
Hard Wait in UFT
So you can add a wait statement that will wait for 10 seconds.
1 2 3 4 5 |
SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe", "http://newtours.demoaut.com/" Wait(10) Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "TestUser1" |
Since you are adding a hard wait of 10 seconds. It means that even if the page gets loaded within 4 seconds, UFT will still continue to wait for 6 more seconds. Hence it is not a good approach to insert a hard wait where the wait time varies between 3 to 10 seconds. The hard wait should not be used where the wait time exceeds more than three seconds.
WaitProperty | Dynamic Wait in UFT
We should always use dynamic wait rather than hard wait where we are not sure how much time an object would take to load. In order to use dynamic wait in UFT, we can use WaitProperty method.
Syntax
object.WaitProperty (PropertyName, PropertyValue, [TimeOut])
Arguments
Parameter | Description |
PropertyName | Required. A String value. The name of the property whose value is checked. |
PropertyValue | Required. A Variant. The value to be achieved before continuing to the next step. |
TimeOut | Optional. A long integer value.Time in milliseconds. After which UFT continues to the next step if the specified value is not achieved. If no value is specified, UFT uses the time set in the Object Synchronization Timeout option in the Run pane of the Test Settings dialog box. Default value = -1 |
We can replace the hard wait in the aforementioned example with the dynamic wait as shown below.
1 2 3 4 5 |
SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe", "http://newtours.demoaut.com/" Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").WaitProperty "isContentEditable",True,10000 Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "TestUser1" |
In the above example, UFT will wait up to 10 seconds. If within 10 seconds the UserName field becomes editable UFT will proceed to the next step rather than waiting exactly 10 seconds. Thus the execution time of the test script will decrease and the script will become more robust.
Recommended Posts
- Create User-Defined Functions in UFT
- File Content Checkpoint | PDF File Validation in UFT
- How to Use Test Combinations Generator in UFT
- How to Open Multiple Tests in UFT
- How to Use Insight Object in UFT
- Amazing Facts about Object Repository Manager in UFT
- Understand Local And Shared Object Repository in UFT
- Automation Object Model in UFT One (AOM)
- Mainframe Automation Using UFT One