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.
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.Double-click the test script.
The test script editor opens with the empty test script.
In the test script tree, select the top entry. Then, in the test element configurator, change the name in Name to
First_Script.In the toolbar of the test script editor, click
.A prompt will open.
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.
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.Open the context menu of the
Preparetest case and select Add Action.In the test element configurator, type the text
CloseProjectin Action.The list now shows only the actions whose name or test driver contains the text.
In the list, double-click the
CloseProjectaction of theTestManager.Projectstest driver.The test action uses the
CloseProjectaction.In the toolbar, click
.
In the same way, add a test action with the title
Load projectand the actionLoadProject(Testmanater.Projects)to thePreparetest case.In the test element configurator, on the Configuration tab, below Load project, click the Select V3 Project button.
A dialog will open.
Select the project
D:\Projects\SystemTest_A.projectand then click Open.In the toolbar, click
.
Add a test action
Loginwith the actionLogin (TestManager.Online). In Application state, select the Stop the application option. Then click
in the toolbar.
In the toolbar of the test script editor, click
.The Execute Test dialog will open.
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.

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.
In the test script tree, open the context menu of the top entry
First_Scriptand select Add Test Case. Change the title toCleanup.Add the following test actions to the
Cleanuptest case:Reset (origin) applicationwith the actionResetApplication (TestManager.Online).On the Configuration tab, configure the following values:
Reset Mode: Reset Origin
Application name:
Device.Plc Logic.ApplicationIf the
SystemTest_A.projectproject is open, then you can also drag the application from the device tree to the field.In the toolbar, click
.
Logoutwith the actionLogout (TestManager.Online)Close projectwith the actionCloseProject (TestManager.Projects)

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.
Open the context menu of the
Preparetest case twice and select Add Assignment.The test case contains 2 empty assignments.
Select the first assignment and specify the following values:
Variable:
ProjectPathValue: Directory of the project, for example
"D:\Projects"
Select the second assignment and specify the following values:
Variable:
ProjectNameValue:
"SystemTest_A.project"
Select the
Load projecttest action and click the Parameters tab.Define the following input parameters:
Name:
ProjectPath, Variable:ProjectPathName:
ProjectName, Variable:ProjectName
On the Configuration tab, change the value in Load project to
{ProjectPath}\{ProjectName}.In the toolbar, click
and start the test run.

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.
Open the context menu of the
Cleanuptest case and select Insert Test Case. Change the title toCheck application state after download (stop).The new test case is located before the
Cleanuptest case.Add the test action
iValue1 = 100?with the following values to the test case:Action:
CompareVariable (TestManager.Monitoring)Variable:
Device.Application.PLC_PRG.iValue1Timeout (ms):
500Compare type:
=Compare value:
100
Add the test case
Check application state in runwith the following test actions.Start applicationwith the actionStartActiveApplication (TestManager.Online)and with Timeout (ms):1000iValue1 = 100?Copy the test action from the previous test case with Ctrl+C and Ctrl+V).
iValue2 = 201?with the actionCompareVariable (TestManager.Monitoring)and with the following values:Variable:
Device.Application.PLC_PRG.iValue2Timeout (ms):
500Compare type:
=Compare value:
201
Add the test case
Check application state after resetwith the following test actions.Reset (warm) applicationwith the actionResetApplication (TestManager.Online)and the following values:Reset Mode:
Reset WarmApplication name: for example
Device.Plc Logic.Application
iValue2 = 200?with the actionCompareVariable (TestManager.Monitoring)and with the following values:Variable:
Device.Application.PLC_PRG.iValue2Timeout (ms):
500Compare type:
=Compare value:
200
Test script

In the toolbar, click the
icon. Specify the name of the tester and click Start.The test report shows an error: In the
Check application state in runtest case, theiValue1 = 100?test action has failed because the application incrementsiValue1at startup. The following test actioniValue2 = 201?is skipped.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
.In the toolbar, click the
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.
Open the context menu of the
Preparetest case and select Insert Assignment. Specify the following values:Variable:
ResultPrepareValue:
""
Select the test action
Login. On the Extended Settings tab, in Result variable, specify the variableResultPrepare.Open the context menu of the
Check application state after download (stop)test case and select Insert Choose.Below Choose, select the empty condition, and in the configurator, type the expression
ResultPrepare="Succeeded"in Condition.Select the 3 test cases
Check application state …and click the Edit → Cut command.Select the element
ResultPrepare="Succeeded"and click the Edit → Paste command.The 3 test cases are now located below the element
ResultPrepare="Succeeded".For each test action in the
Cleanuptest 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
.In the toolbar of the test script editor, click the
icon.The test script is saved in the test repository.

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