hikarthiks
hikarthiks

Reputation: 47

Asserting the response data getting failed

I'm executing an URL in JMeter for which the response data will be like

{"RESPONSECODE":1,"ERRORCODE":0,"REGID":123}. 

I need to assert this data for Response code & Error code, so I added Response Assertion to the Thread Group and constructed a regular expression like

/^\w+(?:RESPONSECODE)(?:1)?(?:ERRORCODE)(?:0)?(?:REGID)[0-9]/`. 

Regid will be a random integer. I should not get any other integer for Errorcode but 0. Have also selected Response Message & Contains radio buttons in Response Assertion.

But the assertion failed, even when the response code and error code are as expected.

Upvotes: 1

Views: 414

Answers (2)

Ori Marko
Ori Marko

Reputation: 58862

Notice you can use JSON Assertion with checking Path

$.ERRORCODE

And check Additionally assert value and Match as Regular expression with Expected value:

[0]{1}

This will check that only 0 is return

Upvotes: 2

Dmitri T
Dmitri T

Reputation: 168157

  1. Change "Field to test" to Text Response
  2. Change your Regular Expression to look like:

    {"RESPONSECODE":(\d+),"ERRORCODE":0,"REGID":(\d+)}
    

Also be aware that there is a JSON Assertion available since JMeter 4.0 which is way more handy to assert JSON response data type

Upvotes: 1

Related Questions