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.
Select the top element in the list on the Test Scripts tab.
Click
.The list contains the new test script as the name
Unnamed_1(0.0)
.Double-click the test script.
The blank script
Unnamed_1(0.0)
is opened in the test script editor.On the Test Script tab, change the name to
Script ABC
.Click the Save button.
An input prompt opens.
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.
Select the top entry in the test script editor and click
in the context menu.Select the inserted test case. Rename the title to
Prepare
. Save the script.Select the inserted test case and click
in the context menu.Select the inserted test action. Rename the Title to
Close project
.On the Test Action tab, click the Select Action link.
The Select Action dialog opens.
In the TestManager.Projects category, select the CloseProject action.
Select the test case Prepare and click .
Change the Title of the inserted action to
Load project
.On the Test Action tab, click Select Action. In the TestManager.Projects category, select the action LoadProject.
On the Configuration tab, at the parameter Load project, select the project
SystemTest_A.project
.Add a test action
Login
. For the test action, click the action . Set the Application state to Stop the application.Click the Save + Run button.
The Execute Test dialog opens.
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
Select the test action Login.
Click
.Add the
Set communication path
action as described above. To do this, select the 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).
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
).
Select the top entry
Script ABC
in the test script editor and click . Change the title toCleanup
.- . Add the following actions below this test case:
Reset (origin) application
( )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
( )Close project
( )
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.
Select the test case Prepare.
Click
.Run the command again.
Two blank assignments are inserted.
Select the first assignment and specify the following parameters:
Variable:
ProjectPath
Value: Directory path of the project (example:
"D:\Projects"
)
Select the second assignment and specify the following parameters:
Variable:
ProjectName
Value:
"SystemTest_ABC.project"
Select the Action: LoadProject.
Click the Parameters tab.
Define the following two input parameters:
Name:
ProjectPath
, Variable:ProjectPath
Name:
ProjectName
, Variable:ProjectName
For the test action Load project on the Configuration tab, change the Load project entry to
{ProjectPath}\{ProjectName}
.Save and start the test script.
Testing the variable values of the controller
Extend the script to check variable values.
Select the test case Cleanup and add the
Check application state after download (stop)
test action.Add the test action
"iValue1 = 100?"
.Action:
Variable:
Device.Application.PLC_PRG.iValue1
Timeout (ms):
500
Compare type:
=
Compare value:
100
Add the test case
Check application state in "run"
.Add the
Start application
test action.Select the
test driver action.Timeout (ms):
1000
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
Add the test case
Check application state after reset
.Add the test action
Reset (warm) application
.Select the
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
Click the Save + Run button.
The Execute Test dialog opens.
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.Select the test action
"iValue2 = 201?"
.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
.
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 asFailed
.
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.
Select the test case
Prepare
.Click
.Specify the following parameters:
Variable:
ResultPrepare
Value:
""
Select the test case Login. Switch to the Extended Settings tab and define the result variable
ResultPrepare
.Select the test case
Check Application state after download (stop)
.Click
.Select the element <blank condition> in Select.
Specify the following parameters:
Condition:
ResultPrepare="Succeeded"
Select the three test cases Check Application (multiselection).
Click
.Select the element ResultPrepare="Succeeded".
Click
.The three test cases are added below the element ResultPrepare="Succeeded".
Select the test action Reset (origin) application.
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
.
Select this option for all test actions in the test case Cleanup.
Save the test script.
The test script is created and saved in the repository.