Qtp 简明教程

QTP - Record and Playback

记录测试相当于记录被测应用程序的用户操作,以便 UFT 自动生成可以播放的脚本。如果初始设置完成正确,则记录和回放可以让我们初步了解该工具,以及它是否能支持该技术。

Recording a test corresponds to recording the user actions of the application under test so that UFT automatically generates the scripts that can be played back. Record and Playback can give us the first impression of the tool, whether it can support the technology or not, if the initial settings are done correctly.

记录和回放的步骤如下 -

Steps for Record and Playback are as follows −

Step 1 − 如下所示,从主页中单击“新建”测试 -

Step 1 − Click "New" test from the Start Page as shown below −

qtp record and run settings step1

Step 2 − 单击“新建”链接时,将打开一个新的测试窗口,并且用户需要选择测试类型。选择“GUI 测试”,为测试命名,并选择需要保存它的位置。

Step 2 − Clicking "New" Link, a new test window opens and the user needs to select the test type. Select "GUI Test", give a name for the test and the location where it needs to be saved.

qtp record and run settings step2

Step 3 − 创建新测试后,将打开新的测试屏幕,如下所示。现在,单击默认创建有 1 个操作的“Action1”选项卡。

Step 3 − Once a New test is created, the new test screen opens as shown below. Now, click the "Action1" tab, which is created with 1 action by default.

qtp record and run settings step3

Step 4 − 单击“录制”菜单,然后选择“录制和运行设置”,如下所示 -

Step 4 − Click the "Record" Menu and select "Record and Run Settings" as shown below −

qtp record and run settings step4

Step 5 − 将打开录制和运行设置对话框,并且根据应用程序的类型,可以选择 Web、Java 或 Windows 应用程序。例如,此处,我们将录制一个基于 Web 的应用程序 ([role="bare"] [role="bare"]http://easycalculation.com/ )。

Step 5 − The Record and Run Settings dialog box opens and based on the type of application, one can select Web, Java, or Windows Applications. For Example, here, we will record a Web Based Application ([role="bare"]http://easycalculation.com/).

qtp record and run settings step5

Step 6 − 单击录制。Internet Explorer 会根据设置自动打开 Web 地址 https://www.easycalculation.com/ 。单击“代数”下的“数字”链接,并且输入一个数字并点击“计算”。完成该操作后,单击录制面板中的“停止”按钮。您将注意到生成以下脚本:-

Step 6 − Click Record. The Internet Explorer opens automatically with the web address https://www.easycalculation.com/ as per the settings. Click the "Numbers" link under "Algebra" and key in a number and hit "Calculate". After completion of the action, click the "Stop" button in the record panel. You will notice that the script is generated as shown below −

qtp record and run settings step6

Step 7 − 现在,通过单击回放按钮回放脚本。脚本回放,并且结果显示出来。

Step 7 − Now playback the script by clicking the playback button. The Script replays and the result is displayed.

qtp record and run settings step7

Step 8 − 结果窗口默认打开,它准确显示执行、通过和失败步骤的时间戳。

Step 8 − The result window is opened, by default, which exactly shows the timestamp of execution, pass and failed steps.

qtp record and run settings step8

Significance of Record and Playback

  1. It is used as the preliminary investigation method to verify if UFT can support the technology/application.

  2. Used to create a test a basic functionality of an application or feature that does not require long-term maintenance.

  3. It can be used for recording both mouse movements and keyboard inputs.

Modes of Recording

  1. Normal Recording − This is the default Recording mode that records the objects and the operations performed on the application under test.

  2. Analog Recording − This records not only the keyboard actions but also the mouse movements relative to the screen or the application window.

  3. Low-Level Recording − This records the exact co-ordinates of the objects independent of the fact whether UFT recognizes the object or NOT. It just records the co-ordinates, hence does NOT record mouse movements.

  4. Insight Recording − UFT records operations, based on its appearance and not based on its native properties.

How to Choose Recording Modes

在单击录制按钮后,一旦录制开始,用户便可以在屏幕上出现的录制窗格中选择录制模式。可以从上述讨论过的模式中进行选择。

After clicking the Recording button, the user can choose the recording mode from the recording pane that appears on the screen, once the recording starts. The selection can be made from any of the ones that has been discussed above.

qtp choosing recording modes

您将会看到,以下场景记录在所有模式中,并且同一样例记录在各种情况下。

You will see that the following scenario is recorded in all the modes and the same action has been recorded under various circumstances.

  1. Launch IE - https://www.easycalculation.com/

  2. Click "Numbers" under "Algebra"

  3. Click "Square Root" link

  4. Enter a value to calculate the square root. Let us say 10

  5. Hit Calculate

在默认、模拟和低级记录模式下记录的脚本如下 −

Script Recorded under Default, Analog and Low Level recording mode is given below −

' DEFAULT RECORDING MODE
Browser("Free Online Math Calculator").Page("Free Online Math
Calculator").Link("Numbers").Click

Browser("Free Online Math Calculator").Page("Numbers Calculator -
Math").Link("Square Root").Click

Browser("Free Online Math Calculator").Page("Square Root
Calculator").WebEdit("n").Set "10"

Browser("Free Online Math Calculator").Page("Square Root
Calculator").WebButton("calculate").Click

' ANALOG RECORDING MODE
Desktop.RunAnalog "Track1"

' LOW LEVEL RECORDING MODE
Window("Windows Internet Explorer").WinObject("Internet Explorer_Server").Click
235,395

Window("Windows Internet Explorer").WinObject("Internet Explorer_Server").Click
509,391

Window("Windows Internet Explorer").WinObject("Internet Explorer_Server").Click
780,631

Window("Windows Internet Explorer").WinObject("Internet Explorer_Server").Type
"10"

Window("Windows Internet Explorer").WinObject("Internet Explorer_Server").Click
757,666

使用 Insight 记录模式的记录如下 −

The recordings using insight recording mode will be as shown below −

recording mode comparison