Looping through DS uses last occurrence of variable in subsequent runs

goofy78270goofy78270 Posts: 126

When looping through a datasource, such as per user login, and utilizing the same variable in multiple steps, the last variable assignment from the first run is used in all subsequent runs.

In the attached, i am simulating the looping through a user list (datasource), which I assigned as a header for ease of tracking. Within each test step, I assign a search value to be used. Each test step works fine if it is ran individually (1 row from DS), but when I run multiple rows, the search value from the bing test, is used in the google search, rather than being reset to the variable assigned in that test suite.

Is this expected functionality or a bug (maybe known issue already)? Is there a workaround to have each run use the variables assigned at the specific test suite level?

This is a simple example of the issue we are facing, but hopefully it gets the point across.

Comments

  • benken_parasoftbenken_parasoft Posts: 1,011 ✭✭✭
    edited August 3

    The behavior of test suite variables intentionally follows that of data bank columns. Please allow me to explain:

    • Test suite variables get initialized once, the very first time the suite that declares the variable is executed. In other words, test suite variables do not get re-initialized to the "local value" each time the suite starts running again.
    • Test suite variables are not scoped to the test suite where they are defined. After the variable is defined, it is accessible to any test that executes after that, just like a data bank column.
    • You can't actually define multiple variables (or data bank columns) with the same name. If you define more than one variable (or data bank column) with the same name then they are actually both referring to the same thing and not two different things.

    So, things happen like this:
    1. Row 1: Your "google" suite executes, initializing the variable to "StarWars".
    2. Row 1: Your "bing" suite starts running, initializing the same variable to "Parasoft".
    3. Row 2: Your "google" suite runs again, using the variable with its current value of "Parasoft".
    4. Row 2: Your "bing" suite runs again, using the variable with its current value of "Parasoft".

  • benken_parasoftbenken_parasoft Posts: 1,011 ✭✭✭
    edited August 3

    Is this expected functionality or a bug (maybe known issue already)?

    The behavior is intentional, by design, to behave the same as data bank columns. There is an old feature request to add additional configuration options related to scoping and/or automatic re-initializing of variables. However, there are currently no plans to implement any such enhancement.

    Is there a workaround to have each run use the variables assigned at the specific test suite level?

    You could add an Extension Tool at the front of each child suite to explicitly initialize the variable to the desired value. The Extension Tool could also be added as a set-up test to each child suite.

    Example (groovy):

    void initVariables(def input, def context) {
        context.setValue("subTS_search", "StarWars")
    }
    
Sign In or Register to comment.