HTTP request on JMeter test failure - jmeter

In my JMeter test, if there is any error, I want to trigger HTTP request to post a message on my system for further attention. What can I do here? Mail visualiser works fine to report errors over email. I want to do the same but over HTTP request. I am using jmeter 3.2.

You can do something like:
Add If Controller after the HTTP Request sampler and put the following code into "Condition" area:
`!${JMeterThread.last_sample_ok}`
Add SMTP Sampler as a child of the If Controller and configure your email server details, credentials, message, etc. there - see Load Testing Your Email Server: How to Send and Receive E-mails with JMeter article for more details.
JMeterThread.last_sample_ok is a pre-defined JMeter Variable holding the result of previous sampler execution, it is true if previous sampler is successful and false otherwise. Due to the If Controller the SMTP Request sampler will only be executed in case of HTTP Request sampler failure which seems to be something you're looking for.

Related

403 forbidden error in jmeter but api works fine in postman

I have an API that is running in GET method. It works fine in postman with 200 status code. But when I try to run the API in jmeter it throws 403 forbidden error. I have configured the debug sampler and tried to re-run the test. The debug sampler passed with 200 but http request still fails.
I have tried to correlate but even that fails.
I removed the port number from the HTTP request, it still fails.
I have added the authorization manager and enter the username and password still fails.
HTTP cookie manager and cache manager added in the script.
As per HTTP Status Code 403 description
The HTTP 403 Forbidden client error status response code indicates that the server understood the request but refuses to authorize it.
This status is similar to 401, but in this case, re-authenticating will make no difference. The access is permanently forbidden and tied to the application logic, such as insufficient rights to a resource.
Most probably you have inconsistencies between requests originated from Postman and from JMeter.
There are 2 possible causes:
You failed to configure JMeter's HTTP Request sampler properly. Given your request works fine in Postman you can try to record it using JMeter's HTTP(S) Test Script Recorder
Prepare JMeter for recording. The easiest way is going for JMeter Templates Feature
From JMeter's main menu choose File -> Templates -> Recording and click "Create"
Open HTTP(S) Test Script Recorder and click "Start"
Prepare Postman for recording.
On Settings page set proxy host to 127.0.0.1 and port to 8888
Execute the request in Postman
JMeter will capture the request and store it under the Recording Controller
Postman uses specific Authorization header which cannot be recorded and replayed. Look into Authorization tab for the request and check which one is used, once you figure out - implement the same in JMeter:
Status Code 403 means you are not authorized to access it, so Ensure you are using the right Authorization for your GET call.
Add cookie manager in jmeter http sampler.

How to filter HTTP request by error code

I run a Jmeter script and getting 200 and 302 HTTP response code in result.
There is no idea to get information to which HTTP request responding 302 HTTP code.
is there in setting or plugin to get better understanding to categorized HTTP request by HTTP response code.
Also need to why 302 error occur and should I need to do something in JMeter Script
Thanks
302 Response code means you that the API you are hitting is redirecting you to another one, this will happen if the follow redirects check box in your HTTP sampler is checked.
You can add View result tree listener at the same lever of your thread group, and from this listener you see the response code for each sampler at the sampler result tab.

"Post" method test result error in JMeter API testing

I tried to run a POST method for API testing in JMeter, I have sent the parameters as needed, but still it shows cannot post.
What should I do to make it work?
user add post request
response message
If you are testing an API my expectation is that you need to send either JSON or XML payload using "Body Data" tab of the HTTP Request sampler.
You will also need HTTP Header Manager to send the relevant Content-Type header
References:
Building a SOAP WebService Test Plan
REST API Testing - How to Do it Right
Another way of building a web service test plan is executing the request(s) according to your test scenario using a 3rd-party tool like Postman or SoapUI and recording them via JMeter's HTTP(S) Test Script Recorder.
In the post request, you need to provide server name or IP address and port number respectively. If it still doesn't work, try changing the path by adding /api then /user/data. it works in some cases.
Hope this works out!

Can I write a script which will send me message when there is heavy load on my server

when there is heavy load applied on my web application I must receive an email, If server is crashed or shutdown I can take necessary action it. How can I do it using jmeter when testing.
JMeter comes with SMTP Sampler which can send emails to individuals or groups. You can use it in conjunction with JMeter Assertions and If Controller, something like
"Normal Sampler" - i.e. HTTP Request
Assertion to check response code, duration, presence of some text, absence of errors, etc.
If Controller with the condition of ${JMeterThread.last_sample_ok}, special JMeter Variable which is true when previous sampler is successful and false otherwise
SMTP Sampler - to send an email
See Load Testing Your Email Server: How to Send and Receive E-mails with JMeter article for example SMTP and Mail Reader samplers configuration

Jmeter - mark the test as failed based on response data

I have written a jmeter test script which automates booking in of cases by sends http post requests to our web application.
At the moment as long as you get a response back from the server it's successfull.
Is there a way it can pass the test only when the response doesn't contain the message error has occured and contains a booking reference
You can use Response Assertion
To test that response does not contain Error message check the "Not":
See also:
https://www.redline13.com/blog/2016/01/what-are-my-options-for-using-assertions-in-jmeter/
You can use Assertions for this.
With this u can lookup the response body, the response code...
Look at this tutorial: https://www.blazemeter.com/blog/how-use-jmeter-assertions-3-easy-steps
You can stop the test if one assertion fails in the thread group (I think).

Resources