3

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

3 Answers 3

6

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

Sign up to request clarification or add additional context in comments.

4 Comments

Hi. I have a regex extractor, which does the job (I can see 'httpCode=200' in the result tree). I tried your suggestion above, as well as just ${httpCode}=="200" - didn't seem to work. What am I missing?
Ok, I have one more insight. My if controller works.. The problem is that I'm trying to extract something depending on the result code. But it seems that if I put the extractor inside the if controller - it no longer has the original result (I'm using JSONPath to extract something).
It sounds really confusing, does you JSONPath extractor works without if controller? Try to put extractor (or multiple extractors) before if controller and then use it's result depending on httpCode.
Seems like JSONPath extractor cannot get access to the response within an if.
4

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.

Comments

1

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}”'.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.