Forum Discussion

wdbian's avatar
wdbian
Occasional Contributor
5 years ago

How to access an array list

an array list variable is declared in the setup script of a test case. To use this list variable in other test steps of this test case, what is needed to do?

Thanks for any answer!

  • wdbian 

     

    Your question made to create this sample project hosted on github

    This smaple project has multiple sample test cases.

    Hope you may find it helpful.

  • nmrao's avatar
    nmrao
    Champion Level 3
    Is it possible to show the line of code how did you do that?

    And in which type of test step is the value required? And in how many such steps the same is needed?
    • wdbian's avatar
      wdbian
      Occasional Contributor

      Actually I want to load external data to a list in the test case setup script, then use this list in the "Groovy Script - Data Source" step. But it seems that the variable declared in setup script cannot be accessbile from test step. 

      • nmrao's avatar
        nmrao
        Champion Level 3
        If that is to be accessed in the groovy script, then there are two ways:
        1. Using context variable. However this works only if the test case is run at one. i.e., it won't work if you run the step separately
        2. Using custom property. Add the data as string (which might read it as string from source as well) and access that property in groovy step and have the logic to convert the string to list.
  • nmrao's avatar
    nmrao
    Champion Level 3

    wdbian 

     

    Your question made to create this sample project hosted on github

    This smaple project has multiple sample test cases.

    Hope you may find it helpful.

    • nmrao's avatar
      nmrao
      Champion Level 3

      wdbian 

      Marking this has solution. If you have questions, please feel to reply.