RADE

Interactive Test Capture

ITC Overview and Using ITC

Recording and replaying interactive scenarios
Technical Article

Abstract

The Interactive Test Capture  (ITC) tool enables you to create automated tests interactively. Automated tests can be used by programmers to manage code quality, detect code regression or instability. An automated test is created by launching V5 using a specific capture mode during which all user interaction are recorded. Once recorded an automated test can be replayed on all V5 supported platforms, independently of the recording platform.

ITC vs. CUT: ITC needs CUT to run since it is completely integrated in mkodt. With ITC you can capture scenarios interactively whereas it is necessary to code the scenario when using CUT. A non developer can use ITC to capture and replay scenarios. Developer skill is needed for failing replay analysis.

This documentation explains how to use ITC and provides some insight on the internal mechanisms used by the V5 capture/replay engine. A sample use case is provided along with a list of known limitations and best practices.


Overview

As programs grow and become more and more complex, ensuring code quality becomes a more and more challenging task. To ensure a good software quality, one might consider a multiple level approach: formal analysis of the source code, automated tests, and manual tests.

ITC is a product dedicated to automated tests. Basically, it allows an interactive scenario to be recorded and replayed. The scenario needs only to be recorded once, and can be replayed as many times as necessary. This provides the developer with a way to make impact analysis or to check for regressions. The tester saves a tedious repetition of manual tests.

The V5 record engine works at "V5 device level": what are recorded are mouse clicks, mouse moves and keyboard events that are translated into V5 system events. Contrary to other commercial automatic test tools, it takes advantage of its full integration into the V5 platform to provide a good stability:

The purpose of ITC is to detect changes between code levels. This happens when a scenario cannot be replayed anymore. When such a thing happens, it is left to the developer's responsibility to analyze whether the failure is a regression symptom or not. In some cases, the failure is normal because the software user interface or its internals have changed. In other cases, the failure is a true regression symptom. A discussion on how to make both stable and relevant automated tests can be found later in this document.

In particular, ITC does not provide any mechanism to ensure stability between a V5 code level and another. No stability is insured between V5 releases, service packs or hot fixes.

Other restrictions are:

[Top]

Basic Tasks

Recording and Replaying

ITC product is accessed through mkodt tool. "-C" option is used for capture. No specific option is necessary for replay.

  1. Create a shell file containing at least the "SetOdtParam TYPE=RECORD" command and the name of the V5 executable to launch. In case of CATIA V5 it will be:
  2.   SetOdtParam TYPE=RECORD
      CNEXT

    Save the file under a given name in the TestCases directory, for instance TestCases/MyRecord.sh.

    In a licensed environment you need to activate the license for CNEXT. Create a FunctionTest/InputData/MyRecord.rec directory, and drop a valid licensing.CATSettings files that will activate the necessary license for capturing and replaying the scenario.

  3. Launch the command
      mkodt -s MyRecord -C

    This starts a V5 interactive session.

  4. Perform your scenario in the V5 session and end it by exiting the application.

    The returned error code should be 0, meaning the record has successfully been captured.

    Notice that the FunctionTests/InputData/MyRecord.rec directory has been created. This directory contains three files: capture.rec, capture.env, and capture.ver.

    More explanations of the content of those files will be given in the record engine internal description section.

  5. Replay the test by launching the command:
    mkodt -s MyRecord

    Notice that the test is replayed on screen. The return code should be 0 if the test succeed.

[Top]

Using Settings

When recording a session, all V5 defaults settings values are used. If your scenario needs to be recorded and replayed with non default setting values, simply put the necessary *.CATSettings files in the .rec directory.

Those setting files are the same that are created and used when launching a normal V5 session.

In a licensed environment, a valid licensing.CATSettings file is needed to activate the necessary licenses for the record and replay scenario.

[Top]

Using P2 UI Level

By default, in capture mode, V5 sessions are launched using the P1 UI level. This is a behavior difference between a normal V5 session and a record capture session. To obtain the P2 UI level you need to put a copy of the FrameGeneral.CATSetting file into the *.rec directory.

It is recommended to use a clean FrameGeneral.CATSettings file. To obtain it, remove your FrameGeneral.CATSettings file in your setting directory, launch a normal V5 session and exit immediately.

[Top]

Opening Documents

Access the necessary files using the File->Open command. Authorized paths for document files are:

Where:

The record engine automatically makes file name and path name conversions to ensure stability when the replay environment differs from the record environment (Unix vs. Windows).

However, to ensure stability when replaying Windows recorded scenario on Unix, make sure that file path entered in the "File Open" or directory chooser dialog box at record time have exactly the same case as the actual directory structure on the machine. Otherwise, the scenario might capture and replay correctly on Windows but fail on Unix.

[Top]

Saving Documents

Saving files can be used to test the save functionality itself or to obtain documents that can be compared to a reference later in the automated test. ITC does not provide such tools for document comparison.

Save the file using the File->Save command. Authorized path for files are:

The $ADL_ODT_TMP directory is deleted at the end of mkodt whereas the content of "Output" is kept. To avoid disk space saturation when replaying a large number of ODTs, use $ADL_ODT_TMP to save documents.

[Top]

Using the Cache System

Cache system location is stored in CATIAV5Cache.CATSettings file. Enter ${ADL_ODT_TMP} in Cache Management directory to make sure that cgr files are generated to a valid directory. Also, this directory is automatically cleaned, avoiding risk of disk saturation.

[Top]

Capture Recommendations, Limitations and Tips

[Top]

Replay Limitations and Tips

[Top]

Common Return Code

Tip

The return code is the return code of the shell passed to mkodt using -s argument [1]. The return code generated by the record engine can be overloaded in this shell. Before making an analysis based on a given return code please check that it corresponds to the actual return code generated by the replay engine.

Code 1

Code 1 is used by the replay engine when the scenario cannot be replayed anymore. Most common situations are:

Code 10

This code applies to problems encountered with dialog objects. Please read the associated message to get a description of the problem. Common situations are:

Code 99

When the allowed time for the test has been spent, mkodt kills the process. This can happen in case of CPU loops, or when the allowed time is not enough to replay the recorded scenario.

Allowed time defaults to 5 minutes. To change this use the SetOdtParam command in your ODT shell. See mkodt documentation [1]. For example to change this value to 10 minutes use:

SetOdtParam max_time=10
Code 100

A CATSession object has not been deleted properly at the end of the process. If the process had a normal termination then this is the symptom of a real CATSession problem. Otherwise, the true cause is to be looked in the abnormal termination of the process.

Other codes

The V5 code includes many integrity checks. Those checks are performed on various domains such as memory management, geometrical modeler, UI implementation, etc. Many of them will generate only a warning or a trace when using a standard V5 session but an error in capture or replay mode. The effect of this is that a scenario that seems to behave well in a standard interactive session will fail to be recorded or fail to be replayed.

This is a powerful tool to ensure good implementation of the V5 infrastructure and non regression when code changes. When this happens an error code will be generated and an error message displayed explaining what is wrong.

[Top]

Debugging Tips

Slowing Down the Replay

Use the CATRecordReplayTimer environment variable to slow down the replay. For example, to have one interaction every 150 milliseconds:

set CATRecordReplayTimer=150      # Windows
export CATRecordReplayTimer=150   # Unix

According to the captured scenario, you can adjust the timer in order to improve the visualization and facilitate error detection.

[Top]

Displaying the Mouse Position

Set the CATRecordVisualDebug environment variable to any value to display mouse position in windows containing a CATViewer. For example:

set CATRecordVisualDebug=1      # Windows
export CATRecordVisualDebug=1   # Unix

Each recorded mouse position is displayed using a red cross. This mode does not correspond to the normal usage of V5, it should be used for debug purposes only and never set in the ODT shell.

[Top]

Advanced Tasks

Using RecordTools

RecordTools is a command line utility that allows you to display and modify the capture.rec file.

Overview

Interactive scenarios are stored in a binary file named "capture.rec". This file contains all the user interactions and necessary information to replay them. RecordTools gives access to the content of this file and provides some editing functionality. It can translate the binary file into a readable xml file format and change the content of an elementary interaction.

RecordTools can be useful to:

Usage

Simply go to the V5 install directory (OS_a\code\bin) and launch RecordTools from the command line.

To display the capture.rec file in xml format, use the -Check option. Use the -h for detailed instructions and display the list of available functionalities.

capture.rec File Content

When recording automated tests, all interactions are stored sequentially in the capture.rec file. An interaction consists in an identifier, a CATCommand path, an event name and optionally a set of data.

Once displayed in xml, the content of the capture.rec file is quite self-explicit.

The following example contains a commented capture.rec file, obtained with the simple following scenario:

<?xml version="1.0" encoding="UTF-8"?>
<Record Version="V5 1.0">
<Source                                                       // Source section
  File="capture.rec"                                          // name of the source capture.rec file
  Vendor="DASSAULT-SYSTEMES"
  Tool="RECORD"
  Version="1"
  Date="">
</Source>                                                     
<Interactions>                                               // Interaction section
  <Interaction
    ID="CR1"                                                 // First interaction is triggered automatically 
                                                             // when the V5 main window appears.
    Path="CATCommandSelector/CATApplication/CNEXT/"          // The parent of all CATCommands is a CommandSelector, so all
                                                             // paths begin with "CATCommandSelector/"
    Event="CATDlgResizeNotification">                        // This interaction is a resize of the main V5 window.
                                                             
    <Datas>
      <Data Num="1" Type="CHAR" Value="CATDlgDocument"/>
      <Data Num="2" Type="ULONG" Value="65546"/>
    </Datas>
  </Interaction>
  <Interaction
    ID="CR2"                                                 // Interaction number 2 is activating the "HelpAbout"
                                                             // menu item
    Path="CATCommandSelector/CATApplication/CNEXT/MenuBar/HELP/CmdButton_CATHelpAboutCommand/CATHelpAboutCommand/"
                  // The names in the path are the internal names of the CATCommand.
                  // There are no generic naming rules for the internal name, they might be related
                  // to the End User name or not.
    Event="CATDlgMenuIActivateNotification">
    <Datas>
      <Data Num="1" Type="CHAR" Value="CATDlgPushItem"/>
      <Data Num="2" Type="ULONG" Value="2147483658"/>
      <Data Num="3" Type="INT" Value="0"/>
    </Datas>
  </Interaction>
  <Interaction
    ID="CR3"                                                 // Interaction number 3 is clicking on "OK" button
                                                             // of the "Help About window"
    Path="CATCommandSelector/CATApplication/CNEXT/HelpAboutWindow/"
    Event="CATDlgDiaOKNotification">
    <Datas>
      <Data Num="1" Type="CHAR" Value="CATFrmDialog"/>
      <Data Num="2" Type="ULONG" Value="787978"/>
      <Data Num="3" Type="INT" Value="0"/>
    </Datas>
  </Interaction>
  <Interaction
    ID="CR4"                                                 // Interaction number 4 is clicking on the 
                                                             // "File | Exit" menu item.
    Path="CATCommandSelector/CATApplication/CNEXT/MenuBar/START/CmdButton_EXIT/EXIT/"
    Event="CATDlgMenuIActivateNotification">
    <Datas>
      <Data Num="1" Type="CHAR" Value="CATDlgPushItem"/>
      <Data Num="2" Type="ULONG" Value="2147483658"/>
      <Data Num="3" Type="INT" Value="0"/>
    </Datas>
  </Interaction>
</Interactions>
</Record>

[Top]

Understanding the Internals of the Record/Replay Engine

The record/replay engine is at the heart of ITC. It is an extension of the send/receive model events that is used for all user interactions in V5. Being part of the V5 core provides platform independency all well as some stability related to UI changes.

Principle

How does it work? When user makes an interaction with the keyboard or the mouse, an event is sent by the system to the V5 application. This event is translated into a CATNotification that propagates in V5 using the CATCommand send/receive mechanism. In general this first notification triggers a whole set of cascading CATNotification related to UI changes. What is recorded in the capture.rec file is the first CATNotification of all, and this one only.

At replay time, the record engine just has to make sure that this first CATNotification is sent again, and all the cascading CATNotifications and corresponding associated code will execute as if all was triggered by a real user interaction.

In short, V5 translates the operating system events into its own model event. Those events can be recorded and replayed to simulate real user interactions.

[Top]

Record Information

The V5 record needs to store the whole information necessary to send the CATNotification at replay time. This information serves three purposes:

  1. Identify the instance of the CATCommand that sends the notification
  2. Identify the kind of notification that needs to be sent
  3. Provide additional data necessary to perform the interaction (for example, if the interaction is a mouse move, provide mouse coordinates).
CATCommand Identification

To identify a CATCommand instance, the record engine takes advantage of the CATCommand tree. At capture time, the record engine stores the path from the CATCommand instance to the root of the tree. At replay time, the engine follows this path the reverse way, from the root to the CATCommand instance.

A CATCommand path is a string made of CATCommand names. It begins with the CATCommand parent of all, whose name is "CATCommandSelector" (this CATCommand has the same name as its class name). CATCommand names are separated by "/". The CATCommand instance that sends the notification corresponds to the last of the path.

For the record/replay engine to work, the CATCommand tree must have the following requirements:

In both cases, V5 applications will work fine interactively. However, it will not be possible to make interactive tests using ITC.

The CATCommand path is stored in the capture.rec file for each notification. When the replay engine fails to find the instance of a CATCommand using the path, a "CATCommand not found" error message is generated and the replay fails with code 1.

Notification

The notification corresponds to the event that is to be sent by the last CATCommand of the CATCommand path. Each Dialog object is a CATCommand and has its own set of notifications, depending on the kind of interaction they support.

For instance, pressing OK button on a CATDlgNotify dialog box corresponds to a CATDlgNfyOKNotification. Clicking with any button of the mouse in a CATViewer corresponds to a CATPressEvent.

Additional Data

Additional data is information necessary to correctly replay the notification. The values stored differ according to the kind of notification that is stored.

For example, in case of a CATMotionEvent, which corresponds to a mouse move over a CATViewer, the data number 3 and 4 are mouse X and Y coordinates. Data number 5 and 6 are the graphic window size.

[Top]

Replay Time

At replay time, interactions are read sequentially in the capture.rec file, and the read notifications are sent by the CATCommand, thus simulating user interactions.

A new notification is sent at each OnIdle event that is generated by the operating system, thus synchronizing the speed of the replay at the maximum machine speed.

During replay all draw requests in the visualization area are not taken into account, except those that come from the CATUpdateEvent which corresponds to draws that were recorded at capture time.

[Top]

Tips to Write Code Compliant with the Record/Replay Engine

[Top]

Tips to Make Pertinent Tests

[Top]


References

[1] Testing Your Frameworks
[Top]

History

Version: 1 [Mar 2004] Document created
[Top]

Copyright © 2004, Dassault Systèmes. All rights reserved.