Bogdan  Dubyk
Bogdan Dubyk

Reputation: 5540

JMeter check if status is 200

In my test plan I have 2 endpoints bid and win. And if bid endpoint return status 200 (it can also return 204, but I need only 200 so I can't use ${JMeterThread.last_sample_ok}) I need to run win endpoint. I did:

  1. create defined variable STATUS_OK

    enter image description here

  2. Create regular expressions extractor under bid request to get response code enter image description here:

  3. Add If controller and insert win request under that controller enter image description here:

But if controller condition not working, Jmeter never run win request.

Any idea why it's not working? or maybe have I can debug it? I would be grateful for any help!!!

Updated including test plan structureenter image description here:

Upvotes: 1

Views: 2555

Answers (2)

Dmitri T
Dmitri T

Reputation: 168072

You need to surround JMeter Variables references with quotation marks like:

"${BID_STATUS}" == "${STATUS_OK}"

Alternatively (better) you can get rid of this Regular Expression Extractor and switch If Controller's condition to use __groovy() function like:

${__groovy(prev.getResponseCode().equals(vars.get('STATUS_OK')),)}

JMeter Groovy Previous Request Status

More information: Apache Groovy - Why and How You Should Use It

Upvotes: 2

Ori Marko
Ori Marko

Reputation: 58772

For If Controller You should use __groovy or __jexl3 function instead

Interpret Condition as Variable Expression? If this is selected, then the condition must be an expression that evaluates to "true" (case is ignored). For example, ${FOUND} or ${__jexl3(${VAR} > 100)}. Unlike the JavaScript case, the condition is only checked to see if it matches "true" (case is ignored). Checking this and using __jexl3 or __groovy function in Condition is advised for performances

In your case use

${__groovy(vars.get("BID_STATUS") == vars.get("STATUS_OK") )}

Or

${__jexl3("${BID_STATUS}" == "${STATUS_OK}")}

Upvotes: 3

Related Questions