Here is the Json Data:
filterKeys":{"${FilterGroup}":["Phenols"]},"lastFilterGroup":"${FilterGroup}"}
I have to extract phenols
from the post request for every filter group this value changes.
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.
Sign up to join this communityHere is the Json Data:
filterKeys":{"${FilterGroup}":["Phenols"]},"lastFilterGroup":"${FilterGroup}"}
I have to extract phenols
from the post request for every filter group this value changes.
Since request payloads have to be composed by yourself, it doesn't make much sense to extract data from there. Makes sense, instead, to fill them with data you take/populate from somewhere.
What could easily be done then, is to populate the request body with variables, so your request body may look like this:
{
"keyword":"${Keyword}",
"maxlength":25,
"offset":0,
"sortKeys":{
"ascending":false,
"attributeName":"relevance",
"type":"ATTRIBUTE"
},
"filterKeys":{
"${filter_key}":[
"${filter_value}"
]
},
"lastFilterGroup":"${filter_key}"
}
And add a JSR223 PreProcessor (using groovy) to that request sampler, where to put values for those variables, like:
vars.put('filter_key', 'analyte');
vars.put('filter_value', 'Phenols');
Otherwise, if you want to extract "analyte" and "Phenol" from that JSON body, given it is a response, you can add a JSON Extractor to the sampler and use the following path expressions
$.filterKeys
to get
[
{
"analyte": [
"Phenols"
]
}
]
and
$.filterKeys.analyte.*
// or
$.filterKeys.${filter_key}.*
to get
[
"Phenols"
]
or other combinations that you can try out on several websites like this.