Assert returned status code HTTP 400 as a success - jmeter

I have been using JMeter for a while and only for load tests. I was wondering if I can use it for ordinary functionality testing.
For example: I have a malformed XML and an application returns 400 Bad Request which I expect to be returned - so it's correct but JMeter resolves it as a failure.
I tried Response Assertions but it didn't work...
Is this possible with JMeter?

To test a non 200 response code, you must check the 'Ignore Status' field in the Response Assertion. Without this, the test will always fail regardless of the response assertion.
So here is what you need to do to test the http response code 400:
Add a new Response Assertion.
Set the following assertion properties:
check the 'Response Code' radio button.
check the 'Ignore Status' box.
check the 'Equals' radio button in the Pattern Matching Rules.
click the 'Add' button.
enter '400' in the row in Patterns to Test.
Done.

Easily.
See answers to this.
You can also possibly try NOT check-box in Pattern Matching Rules Response Assertion.

Related

JSON assertion failing in JMeter

On sending an incorrect username/password, the server application sends this JSON:
{"result":"error","additional-info":"Incorrect username or password"}
I have made the assertion:
Server sends:
But the tree viewer seems to indicate that there is an error. The response log file has this message
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
1606209008151,39,SignInRequest,401,Unauthorized,SignInUsers 1-1,text,**false**,**path can not be null or empty**,570,263,1,1,http://localhost:9000/ws/users/signin,37,0,21
What am I doing wrong in asserting the response?
UPDATE
I added json assertion but when I run the test, the screen looks like this (red color but not sure what the reason is)
Interestingly, if I change the validation from error to "error" then I can see reason (kind of expandable tree) which when using just error doesn't appear.
If you want to compare the full response - you need to go for Response Assertion.
however it's very sensitive to any changes, a whitespace or line break will cause the failure.
JSON Assertion allows executing arbitrary Json Path queries, so if you want to assert additional-info element you should go for something like:
and this one is for result:
You are validating the expected results, so you don't fail
Check Invert assertion checkbox if you want it to fail (or change to success response)
Invert assertion (will fail if above conditions met) Invert assertion (will fail if above conditions met)

How to add assertions to the request inside while controller of Jmeter

I'm using a jmeter script with while controller condition as
${__javaScript("${status}"=="Progress")}
Followed by one http request and from that request again I will extract the status.
If the status is progress it will contine one http request inside loop else if the status success it will exit the loop. But i want to add assertion to ensure whether I get the status as success in the http request or not.
Because if i use assertion as Success in that http sampler, it checks all the reqest and obviously it will return false, and i need to add assertion only to the final http sampler of the while controller.
And so I can get error percentage with failing request in aggregate report and view results tree . Can anyone share your ideas please.
I would recommend using Response Assertion to verify if ${status} variable value is Progress OR Success
Add Response Assertion as a child of the HTTP Request sampler
Configure it as follows:
Apply to: -> JMeter Variable -> status
Pattern Matching Rules: Matches
Patterns to Test: Progress|Success
Given you use "Matches" rule JMeter will treat the pattern as a Perl5-style regular expression so if ${status} variable will be equal to Success or Progress the sampler will pass and otherwise it will be marked as failed.
See How to Use JMeter Assertions in Three Easy Steps article to learn more about using Assertions in Jmeter tests.

How to test an expected 404 response with JMeter

I want to create a JMeter test that will request a page that I expect to return a 404 and assert that that is in fact what is returned.
Typically, JMeter will treat a 404 response as a failure for an assertion.
Create a new Response Assertion under the test.
In the "Response Field to Test" section of the assertion, make sure to check the box for "Ignore Status".
You can then add other assertions as you'd like, such as setting the radio in "Response Field to Test" to "Response Code" and setting the "Patterns to Test" to 404.
(h/t http://jmeter.512774.n5.nabble.com/Making-HTTP-404-a-test-success-tp5713923p5713941.html)
Use a Response Assertion that you add as child of HTTP Request:
Check:
Ignore status so that 404 is not considered an error
Fields to test : Response code
Pattern matching Rules : Equals
Patterns to test : 404

how to make the jmeter sampler result to pass deliberately

I've one simple jmeter login script for negative scenarios which takes invalid login and password.
It gives JSON response as
{
"status": 401,
"error": "unauthorised",
}
The above response is expected.
I've also added the JSON Path Assertion to verify the status code as 401 which validates correctly
Now my target is if I run the test it should pass however its coming as fail status.
Sampler result shows as below
Sample Count: 1
Error Count: 1
How I can make it pass? Is it possible or not?
One more way is to add a BeanShell PostProcessor to that sample with prev.setResponseOK();
This will pass the previous sample irrespective of whatever result it got.
You can try to add Response Assertion to your HTTP sampler and set check-box 'Ignore Status'. Then response will have status 403 and 'Error Count' equals to 0. Does it give result what you want?
Upd: Oops, author has already got the answer. Sorry

Want to check for assertion failure in Jmeter

I am a beginner in JMeter. I want to check for Assertion Failures in my script. I want to continue my transaction for a number of iterations after a single log in attempt, and I want to log out only if an error occurs. For that, I want to check if an error occurred in the script.
Is it possible by comparing assertions in JMeter?
If not, is there are any other way to find that?
Define first indicator(s) that will mark response as erratic (Response Code, keyword, etc.).
Try to use Response Assertion to handle state of your request (success/failure) depending on indicators above and then use IfController along with pre-defined JMeterThread.last_sample_ok jmeter's variable - whether or not the last sample was OK - true/false.
Schema will look like below e.g.:
ThreadGroup
LOGIN REQUEST
...
YOUR HTTP REQUEST HERE
Response Assertion
Response Field to Test: Response Code
Pattern Matching Rules: NOT Equals
Patterns to Test: 200
Regex Extractor
IfController
Condition: ${JMeterThread.last_sample_ok} // will be TRUE if Response Assertion above is TRUE (i.e. response code != 200)
LOGOUT REQUEST
...
In addition to the answer above I would recommend you:
Add error checking to your script - assertions that the responses are
valid for a given reques
Use Firebug to view network traffic when you need to debug your test
script
Use a regular expression extractor to retrieve a dynamic value from a
response and re-use it in a later request
To get the idea you can follow JMeter error checking video tutorial.
FYI: Assertion details provided.
Hope this helps.

Resources