Skip to main content

Creating Test Scripts for System Tests

In the test script, implement the test run from test cases and their actions. The actions are configured test driver actions that communicate with the test system. The system is tested via this communication connection (the monitor interface of the runtime system). Its time behavior determines the time behavior of the test cases.

Usually the test script is programmed to open the test project and set the communication parameters. When the test system is prepared, tests are executed. The test report is generated automatically.

Moreover, you can configure the behavior for failed tests.

Creating a test script

You create a test script and program the test case Prepare. In this test case, actions are executed to prepare the actual test.

  1. Select the top element in the list on the Test Scripts tab.

  2. Click Test Manager → Create Test Script.

    The list contains the new test script as the name Unnamed_1(0.0).

  3. Double-click the test script.

    The blank script Unnamed_1(0.0) is opened in the test script editor.

  4. On the Test Script tab, change the name to Script ABC.

  5. Click the Save button.

    An input prompt opens.

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

    The changes are saved. The script is renamed in the test script editor and in the repository.

  7. Select the top entry in the test script editor and click Add Test Case in the context menu.

  8. Select the inserted test case. Rename the title to Prepare. Save the script.

  9. Select the inserted test case and click Add Action in the context menu.

  10. Select the inserted test action. Rename the Title to Close project.

  11. On the Test Action tab, click the Select Action link.

    The Select Action dialog opens.

  12. In the TestManager.Projects category, select the CloseProject action.

  13. Select the test case Prepare and click Test Manager → Add Action.

  14. Change the Title of the inserted action to Load project.

  15. On the Test Action tab, click Select Action. In the TestManager.Projects category, select the action LoadProject.

  16. On the Configuration tab, at the parameter Load project, select the project SystemTest_A.project.

  17. Add a test action Login. For the test action, click the action TestManager.Online → Login. Set the Application state to Stop the application.

  18. Click the Save + Run button.

    The Execute Test dialog opens.

  19. Specify the name of the tester and click OK.

    The test script is executed. Afterwards, the test log opens with one error.

    The test log shows that the Load project action was successful and that an error has occurred at login because a connection to the device could not be established.

Setting the communication parameters

  1. Select the test action Login.

  2. Click Test Manager → Add Action.

  3. Add the Set communication path action as described above. To do this, select the TestManager.Devices → SetCommunicationPath test driver action. Configure the following values:

    • Device name: <name of your controller>

      Example: Device

      Note: If you have opened the project SystemTest_A, then you can also drag the device here to add them.

    • Gateway name: <name of your gateway>

      Example: Gateway-1

    • Target name: You find this name by scanning the network (in the editor of your device, on the Communication Settings tab).

    _tm_img_first_steps_1.png
  4. Save and start the test script.

    The test script is executed. Afterwards, the test log opens without errors.

    Note: While the script is running, a window opens in the background to show the progress.

Cleaning up the test environment

Closing actions are usually executed after the actual test (for example, in the test case Cleanup).

  1. Select the top entry Script ABC in the test script editor and click Test Manager → Add Test Case. Change the title to Cleanup.

  2. . Add the following actions below this test case:
    • Reset (origin) application (Test Manager.Online → ResetApplication)

      On the Configuration tab, set the following parameters:

      • Reset mode: Reset Origin

      • Application name

        Example: Device.Plc Logic.Application

        Note: If you have opened the project SystemTest_ABC, then you can also drag the application here to add them.

    • Logout (Test Manager.Online → Logout)

    • Close project (Test Manager.Projects → CloseProject)

    _tm_img_first_steps_2.png

Passing a project and path as a parameter

You can use script variables to program the test script as a variable: The project name and the project directory are passed as parameters.

  1. Select the test case Prepare.

  2. Click Test Manager → Add Assignment.

  3. Run the command again.

    Two blank assignments are inserted.

  4. Select the first assignment and specify the following parameters:

    • Variable: ProjectPath

    • Value: Directory path of the project (example: "D:\Projects")

  5. Select the second assignment and specify the following parameters:

    • Variable: ProjectName

    • Value: "SystemTest_ABC.project"

  6. Select the Action: LoadProject.

  7. Click the Parameters tab.

  8. Define the following two input parameters:

    • Name: ProjectPath, Variable: ProjectPath

    • Name: ProjectName, Variable: ProjectName

  9. For the test action Load project on the Configuration tab, change the Load project entry to {ProjectPath}\{ProjectName}.

    _tm_img_first_steps_3.png
  10. Save and start the test script.

Testing the variable values of the controller

Extend the script to check variable values.

  1. Select the test case Cleanup and add the Check application state after download (stop) test action.

    • Add the test action "iValue1 = 100?".

      • Action: TestManager.Monitoring → CompareVariable

      • Variable: Device.Application.PLC_PRG.iValue1

      • Timeout (ms): 500

      • Compare type: =

      • Compare value: 100

  2. Add the test case Check application state in "run".

    • Add the Start application test action.

    • Add the test action "iValue1 = 100?". You can copy this expression from the previous test case. (Ctrl + C, Ctrl + V)

    • Add the test action "iValue2 = 201?".

      • Variable: Device.Application.PLC_PRG.iValue2

      • Timeout (ms): 500

      • Compare type: =

      • Compare value: 201

  3. Add the test case Check application state after reset.

    • Add the test action Reset (warm) application.

      • Select the TestManager.Online → ResetApplication test driver action.

      • Specify the application name and select the Reset Warm option.

    • Add the test action "iValue2 = 200?".

      • Variable: Device.Application.PLC_PRG.iValue2

      • Timeout (ms): 500

      • Compare type: =

      • Compare value: 200

    _tm_img_first_steps_4.png
  4. Click the Save + Run button.

    The Execute Test dialog opens.

  5. Specify the name of the tester and click OK.

    The test script is executed. Afterwards, the test log is displayed (with errors). The test action "iValue2 = 201?" is skipped.

  6. Select the test action "iValue2 = 201?".

  7. Select the Execute even on previous failure option on the Extended Settings tab.

    The symbol of the test action is displayed with an exclamation mark _tm_img_first_steps_5.png.

  8. Save and start the script.

    The test log is displayed (with errors). The test action "iValue2 = 201?" is executed successfully, but the test case is identified as Failed.

Customizing the error handling

Adapt the test script so that the variable test is performed only when the preparation is successful (test case: "Prepare"). You do this by means of the Select action. Then the variable ResultPrepare, which was set in the previous test action, is evaluated.

Furthermore, the actions in the test case Cleanup should always be executed, regardless of the results of the previous tests.

  1. Select the test case Prepare.

  2. Click Test Manager → Add Assignment.

  3. Specify the following parameters:

    • Variable: ResultPrepare

    • Value: ""

  4. Select the test case Login. Switch to the Extended Settings tab and define the result variable ResultPrepare.

  5. Select the test case Check Application state after download (stop).

  6. Click Test Manager → Add Selection.

  7. Select the element <blank condition> in Select.

    Specify the following parameters:

    • Condition: ResultPrepare="Succeeded"

  8. Select the three test cases Check Application (multiselection).

  9. Click Edit → Cut.

  10. Select the element ResultPrepare="Succeeded".

  11. Click Edit → Paste.

    The three test cases are added below the element ResultPrepare="Succeeded".

  12. Select the test action Reset (origin) application.

  13. Select the Execute even on previous failure option on the Extended Settings tab.

    The icon of the test action is displayed with an exclamation mark _tm_img_first_steps_5.png.

  14. Select this option for all test actions in the test case Cleanup.

  15. Save the test script.

    The test script is created and saved in the repository.