|Synchronization in QTP/UFT
Synchronization in QTP/UFT:
Synchronization makes available a specified amount of time for an object to process before moving to next step
. So when we run a test or component(in BPT
) our application may not always respond with the same speed as our computer does. As the process it little complicated with client server architecture. Once the request goes to server, it process the request and sends the result back to client browser or client application.
Now in the client the UFT/QTP is running in full speed. This cause the synchronization issue.In summary the synchronization takes care between the timing issue between UFT,browser and server.
Let’s look into a live example.
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/UFT 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/UFT 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.
Below are the scenario where it is required to use synchronization:
- For client server communications to finish.
- For a window or popup message to open.
- For a screen to change its component status like button gets enabled or disabled/ based on some dropdown the other dropdown values change etc.
- For the progress bar to complete 100%.
- For completing the transaction.
- For a web page to load.
So we can handle a synchronization issue by anticipated time and by synchronization our test or component to ensure the required component and script is ready to take up next step.
Methods available in UFT/QTP to cope up with Synchronization
There are several methods available in QTP for synchronization.
- Inserting Wait statements.
- Inserting waitproperty
- Inserting Synchronization points.
- Increasing Tool default synchronization time.
- Sync Method (Only for WEB)
- Exist Property
- Increasing default time amount.
Inserting Wait Statements:
We can insert wait statements in our test in order to make QTP/UFT 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.
Wait() method is a forcible wait.
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 Milliseconds
- 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 milliseconds.
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
Exist() method is also a forcible wait.
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.
The syntax is as follows:
until ie.readyState = 4 loop
However they are not that reliable.
A sure fire Approach:
We can change the code a little bit
until Browser().Page().Object.Exits(2) loop
Another approach I liked:
WaitForObject = false
Setting("DefaultTimeout") = 500
for i = 0 to 30 'or more
If obj.Exist Then
WaitForObject = true
Setting("DefaultTimeout") = 20000 ' or other value
To my point of view the best approach is
'METHOD NAME : F_Sync
'ARGUMENTS : obj,Max_Wait,result
'DESCRIPTION : Waits for Oracle Navigator
'RETURNS : None '
Function F_Sync (obj,Max_Wait)
Dim Wait_Time flag_wait = "False"
If obj.Exist(2) then
If Wait_Time> Max_Wait Then
loop until flag_wait = "True"
obj will be
Instead of String we can use boolean as well.