Introducing TestComplete's Keyword Tests
To create functional tests with earlier versions of TestComplete, you had to record or write script code that simulated the desired user actions. You used scripts to create flexible and powerful tests. The scripting approach was sometimes difficult for inexperienced users who had no programming or scripting background.
TestComplete 7 introduces a new test type that makes life a lot easier for new testers or people not familiar with scripting – keyword tests. These tests consist of operations (keywords) that correspond to testing actions (like mouse clicks, keystrokes or menu selection). The operation’s parameters specify the tested object, the action to be simulated and its parameters.
Like script code, keyword tests can be recorded or created from scratch in a special editor. In earlier versions of TestComplete you always started with recording a script routine and that was the “main” test type. With TestComplete 7 you can choose the main automated test type (keyword test or script) by using the appropriate menu item:
Here is an example of a keyword test in the editor:
As you can see, the keyword test has a tree-like structure. Nodes that are grouped together correspond to windows and processes of that tested application. Child nodes correspond to actions that are executed over a window or process. All of the user actions that were recorded over a window are displayed under the appropriate grouping node in the editor. This makes the test structure easy to understand and much clearer than “plain” script code.
Also, the new Map object names automatically setting of the recording engine enables TestComplete to automatically create human-friendly names for tested objects during recording. So, now, it’s even easier to determine which object corresponds to an operation. The new naming scheme along with the group nodes help you better understand what actions your keyword test performs.
The editor columns specify the object name, the action to be performed (Click, Keys, Close and others), the action parameters and a brief description. All keyword test operations have a scripting analogue and do the same actions as the appropriate script methods and statements.
TestComplete offers a lot of built-in operations that let you perform a wide range of automated testing:
- Simulate user actions
- Perform comparison and verification actions
- Run other tests from your keyword test
- Check operation result
- Plus more
All of the available operations are located in the Operations panel, which make them easy to get to and use:
The most frequently used operations is the On-Screen Action. It simulates user actions over windows and controls by calling the window’s or control’s method or property. There are also other operations that perform other tasks for automated testing.
If a built-in operation does not exist for your particular need, you can use special operations that run code snippet, script routines or simply call the method of the desired object:
There are also special operations that correspond to script statements like
while loops, or the
if... then statement:
These operations make keyword tests very similar to script routines, but without needing the knowledge of how to write script code. By adding them to your test, you can easily implement the same structure of operations that you can in script code.
To append a new operation to your keyword test, select the operation in the Operations panel and then click within the test to specify the operation’s position. TestComplete will then open the Operation Parameters dialog, where you specify the desired parameter values. The dialog may contain several pages, depending on the operation. Typically, on the first page you select the tested object; on the second page you specify the action to be simulated and on the third page you set the action’s parameters. The following image shows the first page of the Operation Parameters dialog that is shown when you add the On-Screen Action operation to your test:
To modify operation parameters, double-click the desired operation in the editor. This will invoke the same dialog that you used to add the operation.
Like script routines, keyword tests may have parameters and variables.
Using the parameters you can parameterize your tests with external data and make them more flexible. For instance, if you have several operations that simulate user input into controls of a form, you can pass the needed data to your test through parameters and then assign the test parameters’ values to operation parameters:
This feature lets you re-use the same keyword test to simulate input of different sets of values. This is a very convenient for data-driven testing.
As for keyword test variables, they are similar to project or project suite variables and let you store data during the test run and pass them from one operation to another:
If your test fails to execute properly, you can debug it and find the cause of the problem. For instance, you can set a breakpoint on a line in the keyword test editor and then step through the rest of the test (operation by operation) using the same Step Over and Trace Into commands that you use to debug script code:
During the run, you can also evaluate variables and expressions with the Evaluate dialog and use TestComplete’s debugger-specific panels like Call Stack, Watch List and Locals to better understand what happens in your keyword test. All of these panels and dialogs display information that is relevant to your keyword test.
The keyword test and script debuggers are seamlessly integrated. If you debug a keyword test and trace into an operation that calls a script routine, TestComplete will automatically bring up the Code Editor with the script code of this routine and you will be able to go through the script statements until the routine ends and then TestComplete will return back to the keyword test. Similarly, if you debug a script routine that runs a keyword test, you will trace into the keyword test and go through it operation-by-operation.
One more exciting keyword testing feature is that like other TestComplete subsystems, the keyword testing engine is extendable: you can create custom keyword test operations with the script extension technology, use them in your tests and share them with your colleagues or other TestComplete users. The TestComplete package includes a sample keyword test operation created in this way – Log Attributes. You can find the source of this operation in the c:Program FilesAutomated QATestComplete 7BinExtensionsScriptExtensionsAQAScriptExtensions.tcx file.
As you can see, keyword tests are a simple to use and powerful alternative to scripting and even inexperienced testers can create automated tests with ease. Keyword tests also simplify and speed up the creation of functional tests for advanced users. If you haven’t tried TestComplete 7 yet, or if you are new to TestComplete, download and try it today.