4
votes

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

1 Answers

5
votes

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
        ...