Vipul
Vipul

Reputation: 3

Response Assertion is failing with working RegEx when used correlation.

Response data : renderData":"{\"note\":\"test note\",\"color\":\"\",\"appHeight\":\"203px\",\"appWidth\":\"224px\",\"actionURI\":\"/static/nbapps/notepad/addNote.ejs\",\"mode\":\"INLINE\",\"annotationContainerId\":\"ebook_container\",\"pageXOffset\":0}"

Regular Expression (it's working perfect) - renderData : renderData":"([^}]+pageXOffset.+?})"

Response Assertion (Text Response, contains are selected) - ${renderData} : Assertion error: false Assertion failure: true Assertion failure message: Test failed: text expected to contain /{\"note\":\"test note\",\"color\":\"\",\"appHeight\":\"203px\",\"appWidth\":\"224px\",\"actionURI\":\"/static/nbapps/notepad/addNote.ejs\",\"mode\":\"INLINE\",\"annotationContainerId\":\"ebook_container\",\"pageXOffset\":0}/

why assertion is showing, text expected to contain, when the same text is available in response?

Upvotes: 0

Views: 1230

Answers (1)

Dmitri T
Dmitri T

Reputation: 168092

As per How to Use JMeter Assertions in Three Easy Steps guide:

The Pattern can be either be:

a “string” for “Equals” or “Substring” clauses

a “Perl5-style” Regular Expression for “Contains” or “Matches” clauses

Given you use Contains - JMeter treats the pattern as Regular Expression, it doesn't match anything hence it fails.

So you have the following options:

  1. If you extracted the "interesting" response bit into a JMeter Variable - you can apply assertion to the variable directly, configure Assertion as follows:

    • Apply to: JMeter Variable -> Reference Name from the Regular Expression Extractor
    • Pattern Matching Rules: Equals
    • Patterns to test: add your expected value:

      {\"note\":\"test note\",\"color\":\"\",\"appHeight\":\"203px\",\"appWidth\":\"224px\",\"actionURI\":\"/static/nbapps/notepad/addNote.ejs\",\"mode\":\"INLINE\",\"annotationContainerId\":\"ebook_container\",\"pageXOffset\":0} 
      

      Response Assertion applied to variable

    Just make sure assertion goes below Regular Expression Extractor

  2. You can apply assertion directly to the response, in that case choose "Substring" in the "Pattern Matching Rules"

Upvotes: 1

Related Questions