Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.
read, modify, use and save number
LegacyForum
Posts: 1,664 ✭✭
Comments
-
You'll be happy to know that you do not need to write to and read from a file to accomplish this task. Instead, you can do this with a script that stores the variable within the application.
To create and access this variable you can use the following script in a Method Test:CODEfrom soaptest.api import *
from com.parasoft.api import *
SUITE_VAR = "myVar"
#Select this in the Method dropdown to perform the required tasks
def doSomething(input, context):
myVar = getMyVar(context)
#Do what you like with the variable
#You can return the value of your variable to use to parameterize
#data by myVar = str(myVar) and return SOAPUtil.getXMLFromString([myVar])
#Then, attach a Data Bank to this Method and Add the XPath of the return value
return 1
#This function retrieves your variable, or creates one if it doesn't exist
def getMyVar(context):
myVar = Application.getContext().get(SUITE_VAR)
if myVar == None:
myVar = "0"
Application.getContext().put(SUITE_VAR, myVar)
return int(myVar)
# Call this in doSomething() to increment and save your variable
def incrementAndSave(myVar, context):
myVar += 1
Application.getContext().put(SUITE_VAR, str(myVar))
#Select this in the Method dropdown and run the Method Test to reset myVar
def resetVar(input, context):
Application.getContext().put(SUITE_VAR, None)
return 1
I have added comments in the code to describe what each method is doing.
You can add other methods to perform various tasks in the doSomething() method. Also, you can add other Method Tests to access this variable throughout the test suite. Notice that this is reusable code because you can change the string stored in SUITE_VAR in order to have a brand new, and distinct suite variable.0