Qtp 简明教程

QTP - Synchronization

同步点是待测试工具和应用程序之间的时序接口。同步点是一项用于指定测试脚本的两个步骤之间延迟时间的特性。

Synchronization point is the time interface between Tool and Application under test. Synchronization point is a feature to specify the delay time between two steps of the test script.

例如,单击一个链接可能在 1 秒内加载页面,有时候需要 5 秒,甚至可能需要 10 秒才能完全加载。这取决于各种因素,例如应用程序服务器响应时间、网络带宽和客户端系统功能。

For example, clicking on a link may load the page is 1 second, sometimes 5 seconds or even it may take 10 seconds to load it completely. It depends on various factors such as the application-server response time, network bandwidth, and client system capabilities.

如果时间不一致,则脚本将失败,除非测试人员智能地处理这些时间差异。

If the time is varying then the script will fail, unless the tester handles these time differences intelligently.

Ways to Insert Sync Point

  1. WaitProperty

  2. Exist

  3. Wait

  4. Sync(only for web based apps)

  5. Inserting QTP Inbuilt Synchronization points.

假设我们在 “@{}” 中单击“数字”链接和单击“简单利息”计算器之间需要插入一个同步点。对于上述场景,我们将研究插入同步点的五种方式。

Let us say, we need to insert a sync point between clicking on "numbers" link and clicking on "simple Interest" calculator in "www.easycalculation.com". We will now take a look at all the five ways to insert sync point for the above scenario.

Method 1 − WaitProperty

WaitProperty 是一种方法,将属性名称、值和超时值作为输入以执行同步。它是一个动态等待,因此建议使用此选项。

WaitProperty is a method that takes the property name, Value and Timeout value as input to perform the sync. It is a dynamic wait and hence, this option is encouraged.

' Method 1 - WaitProperty with 25 seconds
Dim obj
Set obj = Browser("Math Calculator").Page("Math Calculator")
obj.Link("Numbers").Click

obj.Link("Simple Interest").WaitProperty "text", "Simple Interest",25000
obj.Link("Simple Interest").Click

Method 2 − Exist

Exist 是一种方法,将超时值作为输入以执行同步。它也是一个动态等待,因此建议使用此选项。

Exist is a method that takes the Timeout value as input to perform the sync. Again, it is a dynamic wait and hence this option is encouraged.

' Method 2 : Exist Timeout - 30 Seconds
Dim obj
Set obj = Browser("Math Calculator").Page("Math Calculator")
obj.Link("Numbers").Click

If obj.Link("Simple Interest").Exist(30) Then
   obj.Link("Simple Interest").Click

Else
   Print "Link NOT Available"
End IF

Method 3 − Wait

Wait 是一个硬编码的同步点,与事件是否发生无关的等待。因此,不建议使用 Wait,并且仅可用于较短的等待时间,如 1 秒或 2 秒。

Wait is a hardcoded sync point, which waits independent of the event happened or NOT. Hence, usage of Wait is discouraged and can be used for shorter wait time such as 1 or 2 seconds.

' Method 3 : Wait Timeout - 30 Seconds
Dim obj
Set obj = Browser("Math Calculator").Page("Math Calculator")
obj.Link("Numbers").Click
wait(30)
Browser("Math Calculator").Page("Math Calculator").Link("Simple Interest").Click

Method 4 − Sync Method

同步方法仅可用于页面加载之间始终存在延迟的 Web 应用程序。

Sync Method can be used only for web applications where there is always a lag between page loads.

' Method 4 :
Dim obj
Set obj = Browser("Math Calculator").Page("Math Calculator")
obj.Link("Numbers").Click

Browser("Math Calculator").Sync
Browser("Math Calculator").Page("Math Calculator").Link("Simple Interest").Click

Method 5 − Inserting QTP Inbuilt Synchronization points

@{}− 进入记录模式。如果用户不在记录模式内,此选项将被禁用。

Step 1 − Get into Recording Mode. This option would be disabled if the user is NOT in Recording Mode.

@{}− 转到“设计”→“同步点”。

Step 2 − Go to "Design" → "Synchronization Point".

@{}− 我们需要选择要作为同步点的对象。在选择该对象后,会像下面所示打开一个对象窗口 −

Step 3 − We need to select the object, which we want to be the Sync Point. After selecting the object, object window opens as shown below −

qtp sync point 1

@{}− 单击“确定”,将打开“添加同步窗口”。选择“属性”、“值”和“超时”值,然后单击“确定”,如以下所示 −

Step 4 − Click OK; the "Add Synchronization Window" opens. Select the Property, Value and Time out value and click OK as shown below −

qtp sync point 2

@{}− 会生成如下图所示的脚本,它与我们之前讨论过的 WaitProperty(方法 1)相同 −

Step 5 − The script would be generated as shown below, which is the same as that of the WaitProperty(Method 1) that we had already discussed −

Browser("Math Calculator").Page("Math Calculator").Link("Numbers").Click

Browser("Math Calculator").Page("Math Calculator").Link("Simple
   Interest").WaitProperty "text", "Simple Interest", 10000

Default Synchronization

当用户未对上述任何一种同步方法使用任何方法时,QTP 仍可使用用户可以调整的固有的对象同步超时。

When the user has not used any of the above sync methods, still QTP has an in-built Object synchronization timeout which can be adjusted by the user.

导航至“文件”>> “设置”>> “运行”选项卡 >> “对象同步超时”,如以下所示。

Navigate to "File" >> "Settings" >> Run Tab >> Object Synchronization Time out as shown below.

qtp sync point 3