How to test 10 threads with JMeter? - configuration

Reach 10 threads
a. The 10 threads should be created in a 1-minute period (i.e. - after 60 seconds, thread number 10 will kick in)
Each thread should
a. Execute an HTTP request to http://blazedemo.com
i. Verify that the word ‘welcome’ is in the body of the response
b. Then, wait for 10 secs
c. Execute an HTTP request to http://blazedemo.com/register
i. Wait 5 seconds before the request is executed.
d. Extract the XSRF token from the response header.
e. Use Beanshell script to log the extracted token to the Jmeter log.

Thread Group configuration to implement 10 users ramping up for 1 minute would be the following:
HTTP Request sampler for http://blazedemo.com/ would be:
To check Welcome text presence use Response Assertion configured like:
To wait for 10 seconds use Flow Control Action Sampler
To open http://blazedemo.com/register add another HTTP Request sampler:
To wait for 5 seconds before request use Constant Timer
To extract XSRF Token use Regular Expression Extractor
I don't know who told you to use Beanshell, you need to make this person aware that since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language as Groovy has much better performance and more features comparing to Beanshell. In order to print the tokens for each user add JSR223 PostProcessor as a child of 2nd HTTP Request sampler and put the following code into "Script" area:
log.info("Token for user: " + ctx.getThreadNum() + " is: " + vars.get("token"));
More information:
Building a Web Test Plan
Building an Advanced Web Test Plan

Related

Jmeter - when there are number of threads are running, the variable from JSON extractor is not working sometimes

I am now using Jmeter to run the test of APIs.
The situation is that I have a login Api which will return a token inside response. I use a JSON extractor to save the token as a variable. Then, I use the ${token} is the header of other requests.
However, I found that when I was trying to run 40-50 threads, the ${token} in some threads would be empty, and caused a high error rate.
Therefore, may I ask is there any method to solve it and why?
Thanks very much.
Try saving full response from the Login API, most probably your server gets overloaded and cannot return the token and returning some error message instead.
There are following options:
If you're running JMeter in command-line non-GUI mode you can amend JMeter's Results File Configuration to store the results in XML form and include the response data, add the next lines to user.properties file:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data=true
and when you run your test next time the .jtl results file will contain response bodies for all the requests.
Another option is using a Listener like Simple Data Writer configured like:
and when you run the test the responses.xml file will contain the response data
Both .jtl results file and responses.xml can be inspected using View Results Tree listener
More information: How to Save Response Data in JMeter

How to run the jmeter thread groups one after another

The situation is next: I need to run the performance tests using jmeter. I have setup several Graphql requests, tested them and they work perfectly. The idea of the flow is next:
The user login to the platform using graphql mutation, and in response headers receives accessToken, which is valid for an hour.
The next graphql request must parce the generated token, and perform the next mutation using this token.
The idea is to test the platform with 250k requests, which takes more than 1 hour, and as you probably understand - the token is expired.
What I have done within my script:
I've created 2 thread groups. In the first, there is a Flow is Control action element, which is setup to pause duration for 3600000 msec. This means that it will run the Login request once per hour.
I'm scraping the token with JSON extractor, and parcing it using the BeanShell post-processor, by the following command:
props.put("accessToken", vars.get("accessToken"));
Second thread group has a Graphql request to perform the 250k requests to the server and uses the token value from HTTP headers:
Bearer ${__P(accessToken)}
Everything works fine, accept the fact, that I don't know how to setup the scenario, where the thread group with login will finish its run, after the second thread group will complete 250k requests.
I've tried adding the loop controller to Login, set as infinite, but the thing that once the second group will complete 250k requests - the run won't be finished, as the Login will be running forever once per hour.
Any ideas?
You can add a Loop Controller or Throughput Controller and configure them to execute these 250k requests followed by Flow Control Action Sampler configured like:
When the sampler is reached - it will tell all the threads in all thread groups to stop.
Also be informed that since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting so it makes sense to consider migration now. Storing a property once per hour with 1 thread is not something you should be worrying but for more resource intensive tasks Groovy behaves much better (for example it has built-in JSON support so you can discard the JSON Extractor)

Extracting value from Json response of POST request in Jmeter using Json Extractor

Post request Json Extractor Get request debug sampler error message I'm using Jmeter for stress testing of my application. Test plan that I'm building has a POST request which creates a user and the next PATCH request updates it. Basically I want to extract user_id from Json response received after POST request and add that id in the body of the next request. For that I use Json extractor in my POST request and when I check Debug Sampler the value is successfully stored. But when I try to use extracted user_id in any subsequent requests of the same thread it is not recognized. However when I tried to extract user_id of already created user with GET request then this user_id is normally recognized by other requests. I'm not sure whether Json extractor is not normally used with POST requests or I'm doing something wrong.
It's impossible to provide an answer without seeing the screenshot of your Test Plan or even better Schematic View (the option is available under "Tools" main menu entry since JMeter 5.1)
Given you're able to see the extracted value in the debug sampler I can think of 2 possible options:
Your syntax of referring the user_id variable is wrong, in JMeter the Variables are accessed like ${user_id}
Placement of your JSON Extractor is wrong, i.e. instead of putting it as a child of a specific sampler you have it at the same level as all Samplers therefore it's getting applied to the Debug Sampler as well and the extracted value gets overwritten. See Scoping Rules user manual section for more information

Jmeter trigger http request after another http request is succesful. Concurrent requests with condition

I have 2 thread groups
Thread group1:
csv data set configure
{
loop through the csv file(CSVFile.csv) that contain fileNames of json data to post
eg: CSVFile.csv
file1.json
file2.json
.....so on
}
http request (That posts the data to rest api) (lets call it POST request)
{
extracts data from each json file and put it in http body and post to rest api
eg:
extract data from file1.json and post
}
jsr223 post processor
{
extracting data from above http responce and saving it to a file
}
Thread group2:
csv data configure
{
reads data from csv file
}
http request (Perform GET operation on rest api) (lets call it GET request)
{
eg:
GET ip:port/searchParameter=value
}
Now the problem is how to trigger thread group2 every time a iteration of http request of thread group1 is complete and go for iteration 2 without waiting for thread group2 to complete.
eg:
POST request -> file1.json completion should trigger GET request
As the GET request continues to execute
POST request -> file2.json should be excuted concurrently
CAN I DO THIS?
I would recommend removing interim step of saving the response data into a file and read it in 2nd Thread Group, you could achieve the same within the bounds of a single Thread Group using JSON Extractor and JMeter Variables - this approach will be much faster as in-memory operations are very quick comparing to disk IO operations and you will not have to worry about thread groups synchronisation.
However if you would like to keep things as they are you can consider using Inter-Thread Communication plugin which can be used for synchronisation of different Thread Groups basing on simple FIFO queue so 2nd Thread Group will start when it gets the signal from the first Thread Group.
Check out How to Use the Inter-Thread Communication Plugin in JMeter article for more information if needed.
You can install Inter-Thread Communication Plugin using JMeter Plugins Manager
You can using if controller to handle. You check if thread 1 success, you put status success. If fail you put status fail
Thread 2 check status from Thread 1. If success then run http request

How to Run Http Samplers in sequence order (step by step as per the ThreadGroup Order)

Behavior of my application:
HTTP Request Login
..JSON Path Extractor - Im extracting the session id
Debug Sample - Checking the session id
HTTP Request -- Im passing the session id to these requests
HTTP Request -- Im passing the session id to these requests
HTTP Request -- Im passing the session id to these requests
If I run the above script for one time Im getting the expected results above requests are passing step by step process.
If I run the above script with - Number of Threads as 5 .Then Login is hitting for 3 times other urls hitting for 2 times.
I need to run the above script one order for number of times.
I'm not seeing any regular expression extractor which you would need to pass in the session ID from one request to another. Also, if your back end uses cookies make sure to add the http cookie manager.
Here are some good JMeter getting started videos which also cover what you're trying to do:
http://blazemeter.com/blog/jmeter-tutorial-video-series