JSON assertion failing in JMeter - 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)

Related

Response Assertion / Regex Extractor Not Working in JMeter

I'm trying to extract the CSRF token so I can log in, and be able to obtain cookies, but I'm not able to.
I'm able to get a 200 response code when accessing the URL that contains the CSRF token, and I'm able to see it on the browser and the console, but my response assertion is not able to assert anything regardless of me changing the apply to, field to test, and pattern matching rules sections. My regular expression extractor isn't able to get anything either. All the headers to get to the URL are there. Any suggestions?
Forgot to mention, I'm able to get it on one server that's exactly (or should be) exactly the same as this one...
EDIT:
I placed it under the HTTP Sampler that has that response, and here is an example of what I get for my response assertion. I've also added various images.
Unfortunately you didn't share your output, so I cannot tell for sure, but although it seems your RegEx is correct in both cases, it could be that it doesn't match due to some extra spacing.
It appears that you are expecting a valid JSON, so instead of RegEx you could use JSON Extractor and/or JSON Assertion, for which extra spacing will not matter.
Example: if Response Data is
{"token":"12345"}
I can specify JSON Extractor as
(most important line is JSON Path: $.token)
and the result will be variable token with value 12345.
Here's a good online JSON Path tester, which can help you to figure out the right JSON Path.
If your goal is to check presence of a JSON Object with name of token and an arbitrary value I would recommend going for JSON Assertion instead.
Add JSON Assertion as a child of the request you would like to assert.
Use the following JSON Path query:
$.token
JSON Assertion is available since JMeter 4.0
If you still want to go for the Response Assertion - configure it as follows:
Pattern Matching Rules: Contains
Patterns to Test: {"token":"(.+?)"}

Jmeter - Execute code based on Response assertion result

Trying to put some conditional logic in a script to only execute certain steps based on successful validation of a response assertion.
My script:
Main execution thread
- Submit Http request
-- Response assertion code 200 (indicates request successfully submitted)
-- Response assertion contains string (I expect a specific string back if successful)
-- Json extractor (extract the string I tested for in the response for later use)
- Do a bunch of other stuff
My problem is that I only want to execute 'bunch of other stuff' if I get back the expected string (without it everything will fail anyway).
I need a conditional test to only execute if the second response assertion passed.
I've tried using "${JmeterThread.last_sample_ok}" but this gives me an error of If controller: error while processing ... BAD CONDITION...expected true or false
I'm assuming I've placed the 'if' at the wrong point, or just used the condition inappropriately.
Any advice?
UPDATE:
My script currently looks like this:
- If test record is version 0
-- Send http to version 0 api
--- Response code assertion 200
--- Response assertion message contains specific string
--- Json extractor to extract the data associated with the string
-- If "${JmeterThread.last_sample_ok}"
--- Do other stuff
I'm assuming I've placed the If containing 'last sample ok' at the wrong level, or that the fact there's a json extractor as the last previous step that that has upset things.
You're making a mistake in case. Code is "case sensitive".
Here is how If Controller should be configured:
Condition should be like ${JMeterThread.last_sample_ok}==true in If Controller.

How to assert something using response assertion that has different text in Jmeter

I'm trying to make SOAP call in Jmeter and using Response assertion to validate the No Error in the response. It is failing all the time because each xml has different text b/w the tags.
I see my response is in different string like this No Error & No error.
Basically I want to assert that there are no errors by extracting No Error. Is there a way that I use some regular expression here regardless of what text is present in the response assertion?
Thanks
Do you mean case insensitive response assertion?
(?i) ignore case
Check this:
http://jmeter.apache.org/usermanual/component_reference.html#Response_Assertion

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.

Assert returned status code HTTP 400 as a success

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.

Resources