0
votes

I am getting Json response, I have parsed it using jp@gc - JSON Path Extractor and got an element say 'Access_Token'. This Access_Token is dynamic. So I just want to make sure that this element is not null.

Any leads would be much appreciated.

4

4 Answers

6
votes
  1. In the JSON Path Extractor provide Default Value, for example NOT_FOUND

    JSON Path Extractor

  2. Add Response Assertion after the JSON Path Extractor and configure it as follows:

    • Apply To: JMeter Variable -> Access_Token
    • Pattern Matching Rules:

      • Tick NOT
      • Tick Equals
    • Patterns to Test: NOT_FOUND (or whatever you entered into the "Default Value" input of the JSON Path Extractor)

      Response Assertion

See How to Use JMeter Assertions in Three Easy Steps article for comprehensive information on using Assertions in JMeter scripts.

1
votes

Add a BeanShell PostProcessor component after you get your Access_Token and in it check what you want...

if (vars.get("Access_Token") != null) {
    // do something
} else {
    // do something else
}

Depending on your needs, you can do basically what ever you want from here. For example stop the thread, stop the test...

1
votes

Since JMeter 3.0 there is a new JSON Path Processor that you should use instead of the JMeter Plugins one.

See its features in action here:

You can then apply Dmitri T. answer.

0
votes

In jmeter 5 you could try doing something like this:

JSON Assertion