RADE |
Interactive Test Capture |
ITC Overview and Using ITCRecording and replaying interactive scenarios |
Technical Article |
AbstractThe 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. |
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]
ITC product is accessed through mkodt tool. "-C" option is used for capture. No specific option is necessary for replay.
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.
mkodt -s MyRecord -C
This starts a V5 interactive session.
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.
mkodt -s MyRecord
Notice that the test is replayed on screen. The return code should be 0 if the test succeed.
[Top]
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]
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]
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 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]
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]
[Top]
[Top]
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 is used by the replay engine when the scenario cannot be replayed anymore. Most common situations are:
This code applies to problems encountered with dialog objects. Please read the associated message to get a description of the problem. Common situations are:
To ensure non-regression of UI, V5 record/replay checks that visibility and sensitivity of dialog objects on which interactions are made is stable. At capture time the visibility and sensitivity status of the interacted objects is stored along with the nature of the interaction. If this status is different at replay time, then the replay fails.
An exception to this is the contextual menu, on which only the sensitivity check is applied.
When selecting a line in a combo-box or a list-box, the record engine stores the content of the line as a string. This ensures stability towards the change of the order and number of items in the list. When the string is missing at replay time, the replay fails.
When selecting a line in a multi-column list, the record engine stores the whole line as a separate string for each column. At replay time, the selected line is restored based on the content of the first visible column of the CATDlgMultiList. If more than one line matches the item in the first visible column, then the second column is considered, and so on until a match is found.
When a match is found, the content of the remaining column is not tested. If no match is found the replay fails.
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
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.
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]
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]
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]
RecordTools is a command line utility that allows you to display and modify the capture.rec file.
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:
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.
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]
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.
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]
The V5 record needs to store the whole information necessary to send the CATNotification at replay time. This information serves three purposes:
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:
When this situation arise, an indetermination exists to find the correct CATCommand instance. This situation is handled by the replay engine by generating an error message and making the replay fail. This situation is not detected at capture time, so in those cases the recording step will work but not the replay.
Empty names are not supported in CATCommand path at replay time. If this situation arises, the record will succeed but the replay will fail.
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.
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 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]
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]
[Top]
[Top]
[1] | Testing Your Frameworks |
[Top] |
Version: 1 [Mar 2004] | Document created |
[Top] |
Copyright © 2004, Dassault Systèmes. All rights reserved.