问题
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"/
回答1:
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
回答2:
Got the solution by using the \ forward slash escape character.
回答3:
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.
来源:https://stackoverflow.com/questions/36126447/adding-at-the-start-and-end-of-the-asserted-string-in-response-assertion-in-jm