Randomize path in JMeter REST API load testing - jmeter

So I have a REST API that I want to test with JMeter.
I have few different paths in the REST Service.
If we take an example of simple REST service that will calculate based on two values passed in request, I have four different paths
/add
/sub
/mul
/div
Now I want to test this with a 5000 requests but want to randomize the path and the values in request parameters in each request. Also if possible, want to get the results in 4 categories separately for each path.
Can someone please suggest the right combination of elements?
I am very new to JMeter and hence, expect a little elaborated answer. :)

The fastest and the easiest way is using __chooseRandom() function available via JMeter Plugins. The relevant configuration of the HTTP Request Sampler would be:
Path: /${__chooseRandom(add,sub,mul,div,path)} - get a random option and store it into ${path} JMeter Variable
Name: ${path} - change HTTP Request Sampler Label (for separate reporting)
You can install __chooseRandom() and other plugins Functions via JMeter Plugins Manager from the "Available Plugins" tab:
Be aware that your requests will be random hence your test scenario won't be repeatable so I would recommend considering using other test elements instead i.e. Throughput Controller or Switch Controller or Weighted Switch Controller.
See Running JMeter Samplers with Defined Percentage Probability article for above test elements configuration details.

Related

Jmeter Dynamic parallel graphql requests

In perf tests, I have the below scenario.
the first graphql call fetches multiple account numbers
Next, multiple graphql calls are triggered in parallel - one for each account number in the above response. URL is the same, but the request body has different account numbers.
I added a JSR223 postprocessor for the first request and read account numbers into a list (added them to vars). I can read the list in JSR223 sampler but I cannot find how to use the list to make parallel graphql calls.
The number of parallel graphql calls is equal to the size of the list. The url of requests is the same, the account number in the payload needs to be different.
I can only think of using Parallel Sampler, you can dynamically add children (HTTP requests to execute) using JSR223 PreProcessor like:
1.upto(vars.get('var_matchNr') as int, { index ->
sampler.addURL(vars.get('var_' + index))
})
make sure that your var_1, var_2, etc. variables contain the full URL with the parameters
Parallel Sampler and Controller are not the part of official JMeter distribution, they need to be installed using JMeter Plugins Manager
More information: How to Use the Parallel Controller in JMeter

How do I record a script in JMeter which adds a record in a website?

Currently, I am recording a script in jmeter by which I am adding a record in a website , but a problem is that while recording a script I am able to add a record in a website, but once recording has been done and after that if I will run a script again then, a script is not adding a record in a website.
can you please help me with this?
In the absolute majority of cases you will not be able to replay the recorded script without performing correlation.
Modern web applications widely use dynamic parameters for session management or CSRF protection so once you record your test you get "hardcoded" values and they need to be dynamic.
Assuming all above my expectation is that your test doesn't add record due to failed login or something like that. Inspect requests and responses using View Results Tree listener - this will allow you to identify which exact step is failing.
The process of implementing the correlation looks as follows:
Identify the element which looks to be dynamic either manually inspecting request parameters and look for "suspicious" patterns or record your test one more time and compare the recorded scripts looking for the parameters which differ
Inspect previous response and extract the dynamic value using a suitable post-processor. For HTML response times the best option is CSS Selector Extractor. It will allow you to extract the dynamic parameter value and store in into a JMeter Variable
Replace hardcoded recorded value with the variable from the step 2
Repeat for all dynamic parameters
Don't forget to add HTTP Cookie Manager to your Test Plan.

Jmeter record and play scripts for performance testing

I want to do a performance test of a website so i am creating a script that mimics user behaviour. I am using blazemeter to record those scripts and upload it in jmeter. I have two questions:
1) Do the results of a record and play script vary when run on another machine or a different time ?
2) I am getting a 400 bad request error in one of the steps of the recorded script.
What should i do ?
Is there any other way to test the web pages other than record and play ?
The chance of getting a good load test from recording is minimal as modern web applications widely use dynamic HTTP Cookies HTTP Request Parameters for different reasons (security, tracking client state, etc)
So after recording your test scenario "skeleton" most likely you will need to perform so called correlation - the process of
detecting dynamic parameters
extracting them using JMeter Post Processors and storing into JMeter Variables
and reusing the variables where required
Detecting parameters is quite simple: just record your test 2 times and compare request defaults: if you see differences - you will need to perform the correlation.
Extracting dynamic parameters is a bigger story, choosing the right extractor depends on response type, for example:
for HTML response types use CSS/JQuery Extractor
for XML/XHTML and in some cases HTML use XPath Extractor
for JSON - JSON Extractor
for anything else - Regular Expression Extractor which works with any text (including all above response types)
Also be aware that there is a solution allowing to perform JMeter correlation in an automated manner so you won't to detect and handle the dynamic parameter manually, check out How to Cut Your JMeter Scripting Time by 80% article for more details.

Firing multiple soap requests with different data through JMeter

I want to fire multiple soap requests with different data through jmeter and I want all the soap requests to hit the application concurrently. Also I would like to know if I can do the same thing with soap ui? If possible do describe the steps in detail. Thanks in advance.
For JMeter:
Add HTTP Request sampler to your test plan
Add Switch to "Body Data" tab and put your XML payload skeleton there
Substitute the parts of the body you want to parameterise with JMeter Variables or Functions, the most commonly used for parameterisation test elements are:
CSV Data Set Config
__StringFromFile()
__FileToString()
__CSVRead()
For "concurrency" you also have different options:
If you want X threads to execute requests as fast as they can - just specify them in Thread Group
If you want X requests per second - go for Constant Throughput Timer
If you want all requests at exactly the same time - Synchronizing Timer
For SoapUI check out Simulating Different Types of Load article

Test concurrent users with different browsing patterns

So using Jmeter today and whilst I know i can load test a website with concurrent users using threads, loops etc I was wondering if it is possible to setup a test where say 50 users access the website and then each of them browse the site in a different way?
Has anyone done this before or would jmeter not be the tool to use?
Looking for some suggestions or an idea how to do it in Jmeter.
Suppose you have at least the following simple possibility:Random Order Controller.
Implement set of navigation/browsing steps via separate samplers or group of samplers (grouped via e.g. Simple Controller or Transaction Controller - if some steps should be always executed in defined sequence).
This will be "pool" of navigation steps.
Adding all these steps as child samplers to the Random Order Controller let you have different, per user, randomly generated sequence of navigation steps.
In this case you possible have to put your login/logout samplers (if any) out from Random Order Controller. As well you can e.g. use both scenarios with and without login/logout, etc.
Thread Group
...
Login Sampler
Random Order Controller
Sampler A
Sampler B
...
Sampler X
Logout Sampler
...
As well you can also additionally look onto
Random Controller
Switch Controller: e.g. define in csv-file per-user navigation scenarios, read these scenarios during script execution and assign extracted actions to each thread;
Include Controller.

Resources