Varesh Tuli
Varesh Tuli

Reputation: 45

Adding / at the start and end of the asserted string in Response Assertion in JMeter

Assert given value:

"action":"GET /api/invoice_status","description":"[NO_AUTH] get invoice statuses"

Assertion failure message:

Test failed: text expected to contain /"action":"GET /api/invoice_status","description":"[NO_AUTH] get invoice statuses"/

Upvotes: 0

Views: 1048

Answers (3)

Dmitri T
Dmitri T

Reputation: 168092

As per How to Use JMeter Assertions in Three Easy Steps

The Pattern can be either be:

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

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

So if you choose "Contains" mode - JMeter treats pattern as Regular Expression. Either escape meta characters with a backslash - \ or consider switching the Response Assertion into "Substring" mode instear.

Upvotes: 0

Varesh Tuli
Varesh Tuli

Reputation: 45

Got the solution by using the \ forward slash escape character.

Upvotes: 0

Kaushlendra Jha
Kaushlendra Jha

Reputation: 396

It is adding / slashes just to represent properly but it's not an issue. Cross verify your response after running the script, there might be some difference in the response and the text which you are passing in assertion. Also, there is no need to pass complete response in assertion, just pass some important text like success, passed (if present in response) or any other text available in your response and click on contains radio button inside Response assertion

Upvotes: 2

Related Questions