JRun
JRun

Reputation: 3428

JMeter if controller on HTTP response code

I would like for some branch of the test to execute only if the response code from a previous sample returns with a certain HTTP code 200.

I tried the following as the condition to the 'if controller':

"{httpCode}"== "200"

but no luck (and no luck debugging it, debug sampler says nothing)

Thanks

Upvotes: 3

Views: 19716

Answers (3)

Hari
Hari

Reputation: 127

Add the HTTP request inside the "IF Controller" to which all request you want to check the previous result condition and define the following inbuilt JavaScript condition '“${JMeterThread.last_sample_ok}”'.

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 168197

I guess that you just missing $ sign before variable.

Also JMeter exposes a variable called ${JMeterThread.last_sample_ok} which can be true or false. I'd recommend using it instead in your If controller.

Just put ${JMeterThread.last_sample_ok} variable into IF Controller and get pie.

Upvotes: 4

F2nd
F2nd

Reputation: 384

Did you extract response code to variable httpCode beforehand? Use regex extractor for it http://jmeter.apache.org/usermanual/component_reference.html#Regular_Expression_Extractor

Then check value of variable like that:

${__javaScript(${httpCode}=="200")} 

Alternatively, you may use assertion, see https://stackoverflow.com/a/11669393/808594

Upvotes: 6

Related Questions