5

I want to use if controller in my jmeter load testing. The test is:

  1. do a post and get back an access token.
  2. use that access token to get the next link.

My issue:

I have the access token and have used the post-assertion->regular expression extractor and got the access token from he http response. But now I don't know how to use the if control and ask it do next test only if the http response code is 200. And second question is can i still pass my regular expression value of access token into the if loop's http header manager?

attaching the screen shot of my jmeter.enter image description here

1 Answer 1

5

Try to use Response Assertion to handle state of Request_Access_Token request (success/failure) depending on Response Code returned and then use IfController along with pre-defined JMeterThread.last_sample_ok jmeter's variable - whether or not the last sample was OK - true/false.

Schema will look like below:

ThreadGroup
    Request_Access_Token
        Response Assertion
        Response Field to Test: Response Code
        Pattern Matching Rules: Equals
        Patterns to Test: 200
        Regex Extractor          // your Access_Token extractor
    IfController
    Condition: ${JMeterThread.last_sample_ok}   // will be TRUE if Response Assertion above is TRUE (i.e. response code = 200)
        HttpRequest
        // send extracted Access_Token along with request
        ...
Sign up to request clarification or add additional context in comments.

1 Comment

But what happens if, for the purpose of my test, I need to consider more than one status as "OK" (let's say 200 and 302), but only want to make the second request if status was 200 (not 302).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.