Transient Test Suite Variables

LegacyForumLegacyForum Posts: 1,669 ✭✭
edited December 2016 in SOAtest
Creating, Using, and Saving
Hi Everyone,

A lot of this information can also be found in the Scripting API accessible via the Help Menu. The examples here involve variables that will be reset to the initial value of your choosing after each test run.

These are available as far back as 4.5.1 SP2.0, although the GUI has changed a bit. In 5.0.1, you can create Test Suite Variables in the following manner:
  • Click on the Test Suite Folder in which the variable will be stored.
  • Go to the Executions Options tab.
  • Go to the Test Variables tab.
  • Click Add. A new Test Suite Variable appears.
  • Double-click on the Name or Value. A dialog appears in which you can set both Name and Value. The default value is 0 for an integer and false for a boolean. String variables are scheduled for inclusion in future versions.
Now that you have a Test Suite Variable, this code will allow you to access it (assuming you have named the variable "myVar"):
#myVarTSV is a member of the TestSuiteVariable class
myVarTSV = context.getVariable("myVar")

Once you have accessed a Test Suite Variable, you can manipulate it with getValue() and setValue(). Note that this example is not strictly good coding practice but is intended to demonstrate what is happening.
   #getValue() always returns a string
   myVar = myVarTSV.getValue()

   #Cast to int
   myVarint = int(myVar)

   #Increment by one
   myVarint += 1

   #Cast to str
   myVar = str(myVarint)

   #Store myVar to use later in the test run

Now, when the next test runs, myVar will have the incremented value, but the next time you run your tests, it will start with the value determined in the Test Suite Execution Options.
Sign In or Register to comment.