Python scripting examples, Applied python example: writing an array to a file – MTS Multipurpose Elite User Manual
Page 288
Define the custom function
Note:
The MTS TestSuite custom function editor does NOT include Python libraries.
•
Import the resources you will be referencing within your custom function using the
sys.path.append(resourcePath) method:
import sys
sys.path.append(r"C:\Program Files (x86)\IronPython 2.7\Lib")
import random
•
Define the function:
def customFunction(v1, v2, v3):
return [v1, v2, v3, random.randint(100, 200)]
Execute the custom function test environment
•
Perform the function call:
tsVarArray = customFunction(tsVar1, tsVar2, tsVar3)
•
Do something with the results:
print "tsVar1: " + str(tsVar1)
print "tsVar1: " + str(tsVar2)
print "tsVar1: " + str(tsVar3)
print "\ntsVarArray: "
i = 0
for elem in tsVarArray:
i += 1
print " elem" + str(i) + " = " + str(elem)
raw_input()
Python Scripting Examples
MTS TestSuite offers the ability to create custom functions in Python as part of your test development.
Scripts have full access to variables defined as part of the test. Along with the .NET framework libraries,
scripts offer inter-operability with databases and other external systems. IronPython is Microsoft’s
implementation of the Python language running on the .NET framework.
Applied Python Example: Writing an Array to a File
The following example uses the TSCustomFunctionTemplate within the Python Debugger. In this example,
two Python functions are created to allow reading and writing an MTS TestSuite number array variable to
or from a file.
# =================================================
# 1) Initialize custom function test environment
# =================================================
# *** NOTE: Access to TestSuite variables is not available
# within this debugger. ***
# If you will be designing a function which requires access to
288 | MTS TestSuite
Working with Variables