I'm trying to assert http response codes in JMeter. I think this is really simple, but I encountered a problem I cannot fix.
My server can return 2 response codes: 200 and 423. There is no problem with 200, it just works, but I cannot assert 423, I don't know why.
I tried response assertion with the following configurations:
Field to test: Response Code, Pattern Matching Rules: Contains
Patterns to test: 200 - works 423 - does not work 200|423 - 200 works, 423 does not work (wtf?)
I also tried BeanShell Assertion with
Failure = !(ResponseCode.contains("200") || ResponseCode.contains("423"));
It does not work, too. Also I tried to match with the response message to contain "Locked" - does not work. The server Response looks like this:
Thread Name: 10 Users, 100 Repeats 1-10
Sample Start: 2017-05-19 13:06:09 MESZ
Load time: 33
Connect Time: 2
Latency: 33
Size in bytes: 333
Sent bytes:768
Headers size in bytes: 333
Body size in bytes: 0
Sample Count: 1
Error Count: 1
Data type ("text"|"bin"|""):
Response code: 423
Response message: Locked
Response headers:
HTTP/1.1 423 Locked
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
X-Application-Context: application:capacitytest
Content-Length: 0
Date: Fri, 19 May 2017 11:06:08 GMT
Server: Not_available
HTTPSampleResult fields:
ContentType:
DataEncoding: null
The response code is marked blue for a reason in Sampler Result. Don't know why. I'm also logging the response code via Beanshell PostProcessor. It is 423...
Finally I'm asking here for your help. I have no idea what the problem is or could be. Thanks in advance.
If you are talking about HTTP Request sampler JMeter automatically threats HTTP Status Codes above 400 (inclusively) as failed. I would recommend the following setup:
Configure it as follows:
Response Code
Ignore Status
boxMatches
200|423
Assuming above configuration if the status of your request will be 200 OR 423 - it will pass, otherwise it will get failed by the assertion.
See How to Use JMeter Assertions in Three Easy Steps guide for comprehensive information regarding JMeter Assertions.