I am kind of stuck here, so I am new to Jmeter and trying to perform performance testing on bunch of APIs.
So below is the flow with relevant codes.
> HTTP Authorization Manager
> HTTP Sampler (Base API)
> JSON Extractor
> ForEach Controller
> JSR223 Postprocessor (change API Path with if condition)
> If Controller (Check if value is not "true")
> HTTP Sampler
Below is code for JSR223 (So I am checking if the variable from for loop is equal a regex then append additional parameters) and if the a variable path is null or empty then set a variable as "true"
def currentURL = vars.get("currentURL")
def modifiedURL = ""
log.info("currentURL: " + currentURL)
log.info("modifiedURL1: " + modifiedURL)
if (currentURL.equals("example")){
modifiedURL = 'example?parameter1¶meter2'
log.info("modifiedURL2: " + modifiedURL)
} else if (currentURL.equals("example2")){
modifiedURL = 'example2?parameter3¶meter4'
log.info("modifiedURL3: " + modifiedURL)
}
log.info("modifiedURL4: " + modifiedURL)
vars.put("modifiedURL", modifiedURL)
def ifvar = ${__groovy(vars.get("modifiedURL") != "",)}
def condition = ${__groovy(vars.get("modifiedURL") != null && !vars.get("modifiedURL").isEmpty(),)}
log.info("ifvar: " + ifvar)
log.info("condition: " + condition)
Now the if loop is as below
${__groovy(vars.get("modifiedURL") != "",)}
Now last HTTP Sampler is same as base with added paths as endpoint. e.g for 1st HTTP Sampler path is "https://API.com/path1/" and last one is "https://API.com/path1/${modifiedURL}"
But for some reason last one is running with same path as 1st HTTP sampler "https://API.com/path1/", ideally i would expect it to only run twice https://API.com/path1/example?paramete1¶mter2 and https://API.com/path1/example2?paramete3¶mter4
NOTE: I edited the JSR223 to debug further, for some reason in the logs ifvar and condition shows false, even though modifiedURL is not empty or null
I fail to see where do write the value of
modifiedURLinto a JMeter Variable so my expectation is that the last line of your "code" should look like:You might also want to check this
modifiedURLvariable value using Debug Sampler and View Results Tree listener combination, it might be the case your "condition" doesn't work as you expect