Forum Discussion

Buschfunk's avatar
Buschfunk
Frequent Contributor
11 years ago

Returning multiple results from a script

Hello,

In a Groovy script test step I'm defining several properties/variables.

def url_A = "http://localhost"
def url_B = "https://localhost"
def url_C = "https:8443//localhost"


Is it possible to put these URLs into something like an array, Map, Collection, HashMap or else and make this the script result so that I can access the different URLs in other test steps? Let's assume the following pseudo-code

def url_A = "http://localhost"
def url_B = "https://localhost"
def url_C = "https:8443//localhost"

def urlList = [url_A, url_B, url_C]
return urlList


In another test step I'd like to access e.g. urlList[2] to get https:8443//localhost.

Thanks,
Robert
  • Hi,

    You can access the urllist using context variable,

    So in the previous teststep you need to set the context variable property,
    context.setProperty("urlList ",urlList)


    In the next groovy script teststep you can do a get on the property so,
    def urlList = context.getProperty("urlList ")


    You can also try,
    log.info urlList[1] 


    But as Temil said environment feature is better if you want to use multiple endpoints.

    Thanks,
    Jeshtha
  • Buschfunk's avatar
    Buschfunk
    Frequent Contributor
    Thanks for the support. The question is not only about environments. It is about one script generating multiple similar properties which I don't want to each store in a seperate property. The solution with setting the context property is close to that