Skip to main content

Creating Test Scripts for System Tests

In the test script, you implement the test run with test cases and test actions. The test actions are configured actions of test drivers. The test drivers communicate with the test system via the monitoring interface of the runtime system. The time behavior of this connection determines the time behavior of the test cases.

A test script for a system test usually opens the test project first and logs in to the controller. Then test actions stimulate and check the running application of the test project, mostly with the actions of the TestManager.Monitoring test driver. The test report is created automatically.

The test script matches the test project: It reads and writes the variables of the application in the test project. Therefore, you create the test project first and then the test script.

Requirement: The test project SystemTest_A.project has been created and the device is set to simulation mode. See: Creating a test project.

Creating a test script

You create the First_Script test script and program the Prepare test case. The test case prepares the actual test.

  1. In the Test Manager view, on the Test Scripts tab, open the context menu of the test repository and select Create Test Script.

    The new test script Unnamed_1(0.0) is displayed in the list.

  2. Double-click the test script.

    The test script editor opens with the empty test script.

  3. In the test script tree, select the top entry. Then, in the test element configurator, change the name in Name to First_Script.

  4. In the toolbar of the test script editor, click _tm_icon_save_script.png.

    A prompt will open.

  5. Select the Rename the test script option and click OK.

    The test script is saved and renamed, both in the test script editor and in the test repository.

  6. In the test script tree, open the context menu of the top entry and select Add Test Case. In the test element configurator, change the title of the test case to Prepare. Then save the test script.

  7. Open the context menu of the Prepare test case and select Add Action.

    1. In the test element configurator, type the text CloseProject in Action.

      The list now shows only the actions whose name or test driver contains the text.

    2. In the list, double-click the CloseProject action of the TestManager.Projects test driver.

      The test action uses the CloseProject action.

    3. In the toolbar, click _tm_icon_save_script.png.

  8. In the same way, add a test action with the title Load project and the action LoadProject(Testmanater.Projects) to the Prepare test case.

    1. In the test element configurator, on the Configuration tab, below Load project, click the Select V3 Project button.

      A dialog will open.

    2. Select the project D:\Projects\SystemTest_A.project and then click Open.

    3. In the toolbar, click _tm_icon_save_script.png.

  9. Add a test action Login with the action Login (TestManager.Online). In Application state, select the Stop the application option. Then click _tm_icon_save_script.png in the toolbar.

    _tm_img_first_script_1.png
  10. In the toolbar of the test script editor, click _tm_icon_run.png.

    The Execute Test dialog will open.

  11. Specify the name of the tester and click Start.

    The Test Progress window shows the progress. After the test run, the test report will open. All test actions have been completed successfully.

    _tm_img_first_script_testreport_1.png

Important

If you execute the test on a real controller instead of in simulation mode, then set the communication path before the Login test action. To do this, use the SetCommunication (TestManager.Devices) action with the device name, the gateway name, and the target device name.

Cleaning up the test environment

After the actual check, a test script usually cleans up the test environment, for example in the Cleanup test case.

  1. In the test script tree, open the context menu of the top entry First_Script and select Add Test Case. Change the title to Cleanup.

  2. Add the following test actions to the Cleanup test case:

    1. Reset (origin) application with the action ResetApplication (TestManager.Online).

      On the Configuration tab, configure the following values:

      1. Reset Mode: Reset Origin

      2. Application name: Device.Plc Logic.Application

        If the SystemTest_A.project project is open, then you can also drag the application from the device tree to the field.

      3. In the toolbar, click _tm_icon_save_script.png.

    2. Logout with the action Logout (TestManager.Online)

    3. Close project with the action CloseProject (TestManager.Projects)

_tm_img_first_script_2.png

Passing a project and path as a parameter

To make sure that the test script also works with other projects, pass the project name and the project directory in script variables.

  1. Open the context menu of the Prepare test case twice and select Add Assignment.

    The test case contains 2 empty assignments.

  2. Select the first assignment and specify the following values:

    1. Variable: ProjectPath

    2. Value: Directory of the project, for example "D:\Projects"

  3. Select the second assignment and specify the following values:

    1. Variable: ProjectName

    2. Value: "SystemTest_A.project"

  4. Select the Load project test action and click the Parameters tab.

  5. Define the following input parameters:

    1. Name: ProjectPath, Variable: ProjectPath

    2. Name: ProjectName, Variable: ProjectName

  6. On the Configuration tab, change the value in Load project to {ProjectPath}\{ProjectName}.

  7. In the toolbar, click _tm_icon_run_script.png and start the test run.

_tm_img_first_script_3.png

Testing the variable values of the controller

You extend the test script with test cases which check variables of the application. The variables iValue1 and iValue2 are declared in PLC_PRG in the test project.

  1. Open the context menu of the Cleanup test case and select Insert Test Case. Change the title to Check application state after download (stop).

    The new test case is located before the Cleanup test case.

  2. Add the test action iValue1 = 100? with the following values to the test case:

    1. Action: CompareVariable (TestManager.Monitoring)

    2. Variable: Device.Application.PLC_PRG.iValue1

    3. Timeout (ms): 500

    4. Compare type: =

    5. Compare value: 100

  3. Add the test case Check application state in run with the following test actions.

    1. Start application with the action StartActiveApplication (TestManager.Online) and with Timeout (ms): 1000

    2. iValue1 = 100?

      Copy the test action from the previous test case with Ctrl+C and Ctrl+V).

    3. iValue2 = 201? with the action CompareVariable (TestManager.Monitoring) and with the following values:

      1. Variable: Device.Application.PLC_PRG.iValue2

      2. Timeout (ms): 500

      3. Compare type: =

      4. Compare value: 201

  4. Add the test case Check application state after reset with the following test actions.

    1. Reset (warm) application with the action ResetApplication (TestManager.Online) and the following values:

      1. Reset Mode: Reset Warm

      2. Application name: for example Device.Plc Logic.Application

    2. iValue2 = 200? with the action CompareVariable (TestManager.Monitoring) and with the following values:

      1. Variable: Device.Application.PLC_PRG.iValue2

      2. Timeout (ms): 500

      3. Compare type: =

      4. Compare value: 200

    Test script

    _tm_img_first_script_4.png
  5. In the toolbar, click the _tm_icon_run.png icon. Specify the name of the tester and click Start.

    The test report shows an error: In the Check application state in run test case, the iValue1 = 100? test action has failed because the application increments iValue1 at startup. The following test action iValue2 = 201? is skipped.

  6. Select the test action iValue2 = 201?. On the Extended Settings tab, select the Execute even on previous failure option.

    The symbol of the test action now has an exclamation mark _tm_img_first_steps_5.png.

  7. In the toolbar, click the _tm_icon_run.png icon and start the test run.

    The test report shows an error. The test action iValue2 = 201? has been executed, but the test case has the Failed status.

For more information, see the following: StartActiveApplication, ResetApplication, Tab: Extended Settings

Customizing the error handling

You adapt the test script so that the variables are checked only if the Prepare test case was successful. For this purpose, you use the Choose test element. The test element evaluates the ResultPrepare variable. The Login test action sets this variable.

The test actions in the Cleanup test case should always be executed, regardless of the result of the previous checks.

  1. Open the context menu of the Prepare test case and select Insert Assignment. Specify the following values:

    1. Variable: ResultPrepare

    2. Value: ""

  2. Select the test action Login. On the Extended Settings tab, in Result variable, specify the variable ResultPrepare.

  3. Open the context menu of the Check application state after download (stop) test case and select Insert Choose.

  4. Below Choose, select the empty condition, and in the configurator, type the expression ResultPrepare="Succeeded" in Condition.

  5. Select the 3 test cases Check application state … and click the Edit → Cut command.

  6. Select the element ResultPrepare="Succeeded" and click the Edit → Paste command.

    The 3 test cases are now located below the element ResultPrepare="Succeeded".

  7. For each test action in the Cleanup test case, select the Execute even on previous failure option on the Extended Settings tab.

    The symbol of the test actions now has an exclamation mark _tm_img_first_steps_5.png.

  8. In the toolbar of the test script editor, click the _tm_icon_save_script.png icon.

    The test script is saved in the test repository.

    _tm_img_first_script_5.png

For more information, see the following: Insert Assignment, Insert Choose, Tab: Extended Settings,