Synchronization is referred
to waiting time in the sense that if you have an application in which you have 3 steps for example. Let’s say you are recording the steps where the first step is to enter the information, second step is clicking submit button and third step is get the order No.This is like our flight reservation system.Now when you click submit button it may take few seconds to several minutes depending on the application or internet speed. After that we can get the order no.But when you play this in Qtp it does it very fast, it does not wait for processing of information after you click submit button and may try get the order no before it is getting generated which will give error. So, to overcome such problems we insert synchronization point. By inserting synchronization point we are asking QTP to wait till the order no is getting generated and then retrieve the order no.
It is a process of matching the speeds of both QTP and AUT in order to get proper execution and results.So Synchronization acts as a time interface between the tool(QTP or UFT)a and the underlying application(UAT).
Where Synchronization is required:
During test execution QTP gives instructions one by one with same speed, but AUT takes less time for some operations execution and more time for some operations execution, that time we may not get proper execution and results. In order to get proper results in between QTP & AUT synchronization is required.
There are several methods available in QTP for synchronization.
- Inserting Wait statements.
- Inserting Synchronization points.
- Increasing Tool default synchronization time.
- Sync Method (Only for WEB)
- Exist Property
Inserting Wait Statements:
We can insert wait statements in our test in order to make QTP to wait until AUT completes current operation.Wait is a hard-coded delay (wait X number of seconds). Wait should be avoided as much as possible. The script will run faster and more reliably if you use the built in synchronization functions of QTP (WaitProperty or Sync).This command is used to stop QTP(forcefully) for the specified time.If you are very sure within that time frame the Application is bound to open ,It is very smart to use it.
Wait(time in seconds)
Note: If we insert wait statements QTP waits up to maximum time even though operation is completed.Wait is a hardcoded sync point.
Inserting Synchronization point:
Place cursor in desired location>keep tool under recording mode > Insert menu > Synchronization point > show the object > click ok > select property name & Value (True)>enter time in Mille seconds>click ok>Stop recording.
Note: if we insert Synchronization points, it does not wait up to maximum time, after completion of the current operations, it goes to next step immediately.
object hierarchy.waitproperty “property name”,value,time in milli seconds.
Increasing Tool default synchronization time:
File>settings>run tab>increase object synchronization time out>apply>ok
Note: If we increase QTP tool default time that can be applied for all statements in the test, but QTP does not wait up to maximum time unnecessarily, After completion of one statement execution it goes to next statement immediately.
Sync Method: (only for WEB)
Waits for the browser to complete current navigation.
Browser("Yahoo! Toolbar").Page("Yahoo! Toolbar").Sync
Selecting an appropriate Method:
Suppose in our test one or more statements only are taking more time for execution then selecting “Inserting synchronization method” is better.Suppose in our test more statements are taking more time for execution then selecting “increasing tool time out”.Above two are local features but wait statement is Vbscript feature, even though some drawbacks are there in using wait statement, it is better to use wait statement in functions.
WaitProperty takes input as the property name, Value and Timeout value and waits for the property to appear in the screen for the specified Timeout value
object.WaitProperty(PropertyName, PropertyValue, [TimeOut])
(TimeOut Parameter is optional, incase it is not given it would take the default synchronization time “File –> Setting –> Run –> Object synchronization timeout”)
Set object = Browser("CreationTime:=0").Page("Index:=0").Link("text:=Accounts", "html tag:=A").WaitProperty "text","Accounts",3000
Exist takes input as the Timeout value to sync. It waits for the specified timeout value to check if the object has appeared or not.
Set object = Browser("CreationTime:=0").Page("Index:=0").Link("text:=Accounts", "html tag:=A")
If object.Exist(5) Then
Sync Method can be used only for web applications where there is always a lag between page loads.
Browser.Sync or Page.Sync waits for the navigation to complete, which means that the page has been downloaded completely and successfully. This does not necessarily mean that all of the elements of the page have been downloaded (i.e., images, CSS, JS).
Asynchronous browser and scripting:
UFT/QTP does not support asynchronous browser scripting(ajax) in a direct way.For these cases, we can use browser’s readyState or busy property.
However they are not that reliable.