QTP/UFT tutorial for beginners- synchronization between your application and QTP/UFT

Happy Tuesday! I wanted to create a short but very sweet tutorial that covered a very important part of automation. Synchronization. Failure to synchronize your UFT/QTP tool with your application will result in an unstable script that is bound to fail. So let's see how you can simply and quickly add some synchronization in your scripts. Let's use the object I created below for practice.

Synchronize Here

1. Use your object spy tool and click on the button above. Click the copy to clipboard icon, and paste the values in notepad or another document tool.

2. Use the name property and it's value to identify the object uniquely. Your code should look like the following:

Browser("Index:=0").Page("title:=.*").link("name:=Synchronize Here").Click

3. Run it and make sure it works. Adjust the browser index depending on how many windows you have open.

4. Now, let's add some synchronization. Sometimes, a page may take too long to load, and your script will fail because it cannot find a particular object. However, we want our script to run through fully, even though an application load times may be a bit delayed.

If Browser("Index:=0").Page("title:=.*").link("name:=Synchronize Here").Exist(120) Then
    Browser("Index:=0").Page("title:=.*").link("name:=Synchronize Here").Click
End If

I added a simple if statement and set a condition. If the link is found within 2 minutes, then click on it. The great thing about this if statement, is the synchronization is not statically set. I've seen individuals put static wait times of Wait 120. This means that even if the tool sees the object within 1 second, it will wait 2 minutes to click on it. The great thing about using the conditional statement above, if UFT/QTP finds the object immediately, it will click it. Otherwise, it gives the page a maximum of 2 minutes to load all of the objects.  This makes your script a lot more stable and robust. Even if your application is really slow on a specific day, your script will still run fully.

That is all for this tutorial! I will follow this tutorial up by adding some pass fail conditioning for your script. Please post your comments and questions below!

Pin It on Pinterest

Clef two-factor authentication