how to make the jmeter sampler result to pass deliberately - jmeter

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

Related

Jmeter Response Assertion is failing upon getting from Reg Ex Value

Hello I have a scenario where I need to validate the extracted value from my regex, unfortunately I'm encountering an error upon using Response Assertion. I would like to seek assistance to any one of you. Your response is highly appreciated. Thank you so much in advance
I am able to extract my regex upon running, but I encounter upon using that on my Response Assertion.
Screenshot:
Response Screenshot
Response Assertion Failure
Response Assertion Configuration
Expected Result: I just want to validate "userId = 14534"
If you want to just check the presence of 14534 text in the response - just configure the Response Assertion as follows:
In case you want to check whether 1st row of the user_id column of your SQL query result set is equal to 14534:
In the JDBC Request sampler define a variable name, i.e. user_id
Amend your Response Assertion configuration to Apply to a JMeter Variable called user_id_1:
More information: How to Use JMeter Assertions in Three Easy Steps

Jmeter Assertion fails even when Response Status Code is 200

My Jmeter assertion fails even when the response status code is properly returned as 200. Gets the message as
****** received : 200[[[ ]]]
****** comparison: 200[[[
]]]
You have this empty pattern:
Remove it so your Response Assertion would look like:
and it should resolve your issue. Also double check that your 200 pattern doesn't contain line breaks
correct:
incorrect
mind the cursor position
More information: How to Use JMeter Assertions in Three Easy Steps

Complex response assertion in jmeter

I'm struggling a bit to build a proper test for this scenario: basically, I'm making a POST call to a web-service and trying to assert the following:
A 201 response is ok
A 409 response is also OK (but I extract this code to a variable and attempt a retry later)
A 400 response might be OK, but only if there is a certain string in the response body
Items 1 and 2 above I got to work fine: I handle 2 with a Response Code Extractor and an If Controller later on.
My problem is: how do I test for a given substring on the response body, but only in the event of a 400 response code?
The final assertion I want to build goes something like this:
"(if the response code is 201 or 409) or (if the response code is 400 and 'substring' found in the body) then OK"
I believe that you need to use Beanshell Assertion as it is the most flexible of all assertions provided.
Relevant Beanshell code will look as follows:
if (ResponseCode.equals("201") || ResponseCode.equals("409") || (ResponseCode.equals("400") && SampleResult.getResponseDataAsString().contains("something"))) {
Failure = false;
}
See How to Use JMeter Assertions in 3 Easy Steps guide for more details on getting confidence by using JMeter Assertions.

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