Ask a Question

Passing an array element in the "value" field of a test step

SOLVED
_Oliver_
Contributor

Passing an array element in the "value" field of a test step

Hi all,

I need to call a service with a parameter value that should be an array.

The parameter name is officialLanguages and I need the generated URL to look like that

xxxxxxxxxx?officialLanguages=EN&officialLanguages=FR

I cannot figure out how to put these two elements in the value field of the test step. For example, this (see below image) does not work because the whole ["FR","EN"] is considered as one single string and not as an array of two strings.

 

_Oliver__0-1632807491939.png

I tried various combination with and without quotes, with and without brackets etc... but nothing worked.

I found a workaround by disabling URL encoding for this parameter value and by defining the value as shown here :

_Oliver__2-1632807887876.png

But that looks to me like an unorthodox solution...

 

Is there an easier/cleaner way to do that ?

 

Regards

Oliver

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisAdams
Frequent Contributor

Re: Passing an array element in the "value" field of a test step

I'm not sure about a cleaner way in that screen, but another method would be to use a Groovy script step prior to the service call test step which builds the URL based on the array..

 

E.g. 

def rootUrl = "Whttps://www.yyyyy.com/";
def languageArray = ["FR","EN","US"];

def newUrl = rootUrl;

// Iterate over the language array to add each language.
// Note, this is purely an example and needs more work to include the ? and & 
// as appropriate.

languageArray.each{val ->
    newUrl = newUrl + "officialLanguages=" + val;
}

// Setting the next test step Endpoint to be the 'newUrl'....
testRunner.testCase.testSteps["myServiceRequest"].properties['Endpoint'].value = newUrl;

 

 

View solution in original post

4 REPLIES 4
ChrisAdams
Frequent Contributor

Re: Passing an array element in the "value" field of a test step

I'm not sure about a cleaner way in that screen, but another method would be to use a Groovy script step prior to the service call test step which builds the URL based on the array..

 

E.g. 

def rootUrl = "Whttps://www.yyyyy.com/";
def languageArray = ["FR","EN","US"];

def newUrl = rootUrl;

// Iterate over the language array to add each language.
// Note, this is purely an example and needs more work to include the ? and & 
// as appropriate.

languageArray.each{val ->
    newUrl = newUrl + "officialLanguages=" + val;
}

// Setting the next test step Endpoint to be the 'newUrl'....
testRunner.testCase.testSteps["myServiceRequest"].properties['Endpoint'].value = newUrl;

 

 

View solution in original post

_Oliver_
Contributor

Re: Passing an array element in the "value" field of a test step

Thanks a lot @ChrisAdams 

I thought of that, I am just thinking (maybe wrongly) that this is a basic thing and I am therefore assuming that there should be an easier way to handle that without having to use groovy.

But thanks for your script anyway, I am sure I'm going to use, for this issue or for another one 👍

ChrisAdams
Frequent Contributor

Re: Passing an array element in the "value" field of a test step

It is basic, and buiIding dynamic URLs is common, but I genuinely cannot think of a way of doing this without Groovy script.

The problem with this issue is that you're passing in an array so you don't know how many elements hence the slightly more complex looking Groovy.

_Oliver_
Contributor

Re: Passing an array element in the "value" field of a test step

Ok, got it, thanks @ChrisAdams  for your support 👍

cancel
Showing results for 
Search instead for 
Did you mean: