Looping Script Variables Based on Portion of Name

Hello all,

I have a dilemma and I am a little unsure of the best way to accomplish what I want.

I am looking to setup a for loop that looks at all variables for a script and references them in the current iteration. I am looking to use this for iterations in which a single webservice call can return multiple values, based on a single parameter being sent in.

Variable naming:

  • Current/Variable_1
  • Actual/Variable_1
  • Current/Variable_n
  • Actual/Variable_n

with a for loop something like this to replace the values

for (cnt = 1; cnt <= TestObject.variables ; cnt++) {
  curVar = TestObject.variables[cnt]
  if (curVar .name.substring(0,8) = 'Current/') {
    curVarName = curVar.name.drop(8) 
    for (cnt2 = 1; cnt2 <= TestObject.variables ; cnt2++) {
      actVar = TestObject.variables[cnt2]
      if (actVar.name.substring(0,7) = 'Actual/') {
        actVarName = actVar.name.drop(7)
        if (curVarName = actVarName) {
          WS.verifyElementText(response, curVar, actVar)
          or - just additional option for this clause
          Stringx.replace(curVar, actVar)

Current and Actual were used in reference as this structure could possibly be used to update/replace variables within the data of a script such as updating related inputs like test A requires 1 input, but test B requires 3, or validate numerous result elements based on a single iteration for a test suite rather than coding individual test cases for the same process.

Thank you in advance for your time in this matter.


I am not clear on the idea. The implementation looks a little bit complicated and might not be dynamic for different test scenarios.

Sorry for the clarity, let me try and explain a little further.

When creating a test case, as in this instance, for a web service, the call/object is the same for each. However, instead of creating numerous test cases for different scenarios, I would like to make this data driven.


If a request for itemA is supposed to have 3 elements returned, then I would like to be able to loop through the data set to verify those rather than running a separate test compared to a request for itemB, that only returns 2 elements.

This approach comes in handy when creating numerous test in which only the input and outputs vary. Simply adding a couple lines to the data set is much easier than coding a new test case for every different scenario.

In retrospect, this could be a functionality that is already supported…I am just unsure.



Please correct me if I am wrong. I am thinking about the following test flow and approach:
- Create a test case, which received input for criteria (looking for item A, or item B). Get the actual response.
- Create test data set having input criteria as well as expected output response
- In the test case, verify the actual response and the expected response

wow…it is a shame I can’t edit post I have made as i see now how the initial question is not very well depicted…yes, but instead of coding numerous test cases, I would like a single one with the ability to run variables per iteration and through code, state which ones apply as I stated above.

take a web service request for instance (json format)

the request call and structure can be the same, but data for the body elements could be different and return different result elements

Iteration 1 requires 3 input variables and has one 3 elements returned

Iteration 2 requires 3 different input variables and has 2 elements returned

I want to be able to loop through the variables for an iteration to add each input in iteration 1 and verify each result for iteration 1 as well, then so on for 2…n

Since the test case itself is the same, and only the data is different, that would work best to have the data in a single file for a single test case, rather than numerous test cases for every variation

yes, I meant we can create a single test case for calling the request and the test data file will have multiple rows. Each row in the data file will have information of:
- Input value
- Expected output value
I still not understand the variable part. I think that we could be it completely dynamic with expected output specified in the data file. Depend on the expected output, we will parse the response and compare with the output.

since one can define service request as TO in repository, that’s the reason for calling in loop.

my advice - prepare array of TO you really want to use instad of all objects from folder.
also there is automatic way somwhere on forum somebody did script that reads folder on disk, parse object names from that and use it as input for get TO fn().