JMeter HTTP POST based on HTTP GET - java

I am using JMeter to do some testing.
I have to do a HTTP GET on a URL like www.acme.com/documents/next.
This shall return me a document ID, then i need to do a POST based on that document ID like
www.acme.com/document/{document_id}. This document ID shall be the one returned by the previous GET request.
I will need to run this in many threads, so if there needs to be a variable used to store the result of the GET, it should be stored in something like a ThreadLocal because each one will get a unique id when it called the GET method.

You should use postprocessor to extract variable. Your test plan will look like this:
Thread Group
- GET request to /documents/next
--- Regular Expression Extractor (with reference name=variable)
- POST request to /document/${variable}

Related

How to send multiple values in rest url in java

I have a get request like below.
Https://localhost.com:8080/search?date=2021110
I get the result when I make a get request. But my requirement is to get multiple values with 2 status. Like status=2 and status=3
If I modify my url like this
Https://localhost.com:8080/search?status=2&status=3&date=2021110
Why not change the request method to POST. Or you can also use ',' between two values and handle it on server programming.

Create multiple concurrent POST requests, with JSON body having distinct ID value in each request

I need to make around 100 POST request.
The body of every post request needs to have a different ID.
Sample BODY
{
id: 1,
name: "ABC",
city: "NY"
}
All 100 requests should have different 'id' , but rest of the data can be the same
Can I attain this through Postman ? ..or some other tool?
Tried:
Assigned value to a variable, and used that as value for ID in Postman, but unable to change this variable for every request
You can add {{$randomInt}} to the POST body, save that request and then open the Collection Runner.
In the iteration count, type 100 and start the run. That will create a random id value for each request between 1 - 1000. As this is "random" this is the potential for the same value to be sent more than once.
Alternatively, you could add a {{id}} variable to the POST request body. Then create a CSV file with a single column which has id as the header - add the ID values you want as 100 new rows in the column.
In the Collection Runner, select the created CSV file and run that with your request.
There are a number of different ways that this can be done, it's just finding the use case that suits your context.
You can the pre-request scripts in postman to send multiple request.
You can use
postman.setNextRequest("request_name");
To keep sending request till some condition is reached

Jmeter - how to properly send request name and reason on assertion failure

I am new to jmeter (I am using version 3.3) and I created a test plan with the goal of sending an email on Assertion failure.
in this email I want to add some information about the name of the request and its reason
so I have added and if controller with this condition:
${JMeterThread.last_sample_ok}
a beanshell preprocess with this script:
and an SMTP Sampler with this body:
and a response assertion:
I want to get an email anytime it hits the condition of response code=500 and the info described above.
I got to receive the email on that condition but the body message is literally this:
${body}
this is the assertion result:
what am I doing wrong?
How to get what I need?
Thanks
Your prev variable is not defined in the Beanshell PreProcessor (it exists only for PostProcessor and Listener, I would suggest using ctx.getPreviousResult() instead where ctx stands for JMeterContextService instance.
You also need to enable your HTTP Request GET - posts as this will be this "previous result" you're interested in.
Be aware that starting from JMeter 3.1 it is recommended to use Groovy for any form of scripting so consider migrating to JSR223 PreProcessor and Groovy language on next available opportunity. You should be even able to re-use the same code as I don't see any Beanshell-specific features in it. See Apache Groovy - Why and How You Should Use It article for more information on Groovy scripting in JMeter.
The script is sending an email if the last sampler is ok, therefore the assertion is ok too, so the body variable won't hold any value.
Just adjust your if statement to !${JMeterThread.last_sample_ok}, and then move up your HTTP sampler HTTP Request - POST/articles above the if controller.
This will make your script send an email if the sampler failed and you will have the body variable holding the failure message.

How do I access the returned value of a Java Request in JMeter?

I'm trying to create a simple test plan in JMeter to send data over JMS, using a Publisher and a Subscriber. I've got a Java Request which returns a SampleResult object containing a list of subresults, each containing a String ("Hello, world!" + count), and I want to be able to send these Strings over JMS, but I can't work out how to access them.
Everything is working fine in isolation, but how can I plug the result that my Java Request spits out into my Publisher so it can be sent?
Add a Regular Expression Extractor as a child of your Java Request:
You can then use this in your JMS Sampler:
${data}

JMeter: Load testing of a HTTP POST followed by a HTTP GET

I am evaluating performance of my transport library and it will be helpful if I get suggestions on the following:
I use a Junit sampler to perform the following:
HTTP POST test: I send a HTTP POST request: This will cause a DB write. I have to evaluate all the parameters (throughput, avg. response time) holistically for POST + DB_WRITE operation. As response to this POST request, I get a unique id. So if I send 1000 successful POST requests, I will have 1000 unique ids.
Now my question is how can I use these unique ids for my next test case, perform a HTTP GET on each of created unique ids.
I can parse the HTTP POST response and write the unique id into a file and try using that file for my HTTP GET test. But the problem is if I create a thread group of 10 different threads, there will be issues of synchronization on file writing.
Is there any PostProcessor I can use to record results in filesystem?
As for me looks like you can avoid usage of file to store and then read generated id's.
Logic is the following:
execute your POST request;
parse response returned from POST - using Regular Expression Extractor or any other post-processor attached to the request - to extract your ID;
store extracted ID in user-unique / thread-unique variable - in the same post-processor;
how to do this for Regular Expression Extractor see below: ${__javaScript('${username}'+'UnicID')} generates unique variable for each user/thread, to avoid interference in multi-user cases;
seems that can also use threadNum function instead of ${username} variable;
if POST request completed successfully, ID extracted and stored in variable - execute your GET request were extracted ID is used as param;
use ${__V(${username}UnicID)} construction to get back previously saved ID.
You may add also add Debug PostProcessor to POST request sampler - to monitor generated variables and their values.
Seems that's all.
Thread Group
Number of Threads = X
Loop Count = N
. . .
HTTP Request POST
checkingReturnCode // Response Assertion
extractUniqueID // Regular Expression Extractor (e.g.)
Reference Name = ${__javaScript('${username}'+'UnicID')}
Regular Expression = ...
Template = $1$
Match No. = 1
Default Value = NOTFOUND
IF Controller // execute GET only if POST was successful
Condition = ${JMeterThread.last_sample_ok} // you may change this to verify that variable with extracted ID is not empty
HTTP Request GET
param = ${__V(${username}UnicID)}
. . .
Hope this will help.
There won't be any problems with synchronization (they are resolved by file system). In every thread (which is POST-ing) you should open your file for writing and append a new line to it. Again, don't worry about synchronization, OS will take care of it.

Categories

Resources