JMeter http choose different url variable - jmeter

I want to test a resource that gets a token in the URL.
for example: localhost:8080/api/{TOKEN}/function
I want JMeter to choose from a list of 4 different tokens. is it possible?

Everything is possible given JMeter is open source.
If you have i.e. 4 User Defined Variables containing tokens like:
You can get a random one for the each request using __V() and __Random() functions combination like:
${__V(TOKEN_${__Random(1,4,)})}
So you can change "Path" of the HTTP Request Sampler to look like:
/api/${__V(TOKEN_${__Random(1,4,)})}/function
and that should be it. See Here’s What to Do to Combine Multiple JMeter Variables article for more details.

Related

Passing one api parameters value to another api

In JMeter I have two Api , one api generate filename and id then these parameters pass to another api here I used plugin path extractor and also use csv data set config to extract , save and pass parameters and its value to another api but problem is when multiple user it generate multiple filename and id but how to pass those file name and id to every httprequest to another api.
You don't need any CSV Data Set Config, it will be sufficient to
Add a suitable Post-Processor to extract the generated file name
The Post-Processor will store the generated name into a JMeter Variable
You should be able to use the variable in the "2nd API"
As per JMeter Documentation Variables are local to a thread so each thread (virtual user) you define in the Thread Group will have its own value.
Demo:
More information on JMeter Correlation concept: Advanced Load Testing Scenarios with JMeter: Part 1 - Correlations

How can I add/import/include 'IncludeController' in JSR223/Groovy and use it in current TestPlan?

How can I access/use the specific test fragment file (jmx file) in the project use JSR223/Groovy code and use a specific Sampler?
For example, I have test fragments files [patientApi.jmx, doctorApi.jmx], each of these include fragment contains bunch of HTTP Requests (endpoint) with assertions and etc.:
patientApi.jmx:
{uri}/patientApi/getFirstName
{uri}/patientApi/getLastName
{uri}/patientApi/getDoctors
{uri}/patientApi/blaBla
doctorApi.jmx:
{uri}/doctorApi/getFirstName
{uri}/doctorApi/getLastName
{uri}/doctorApi/getPatients
{uri}/doctorApi/blaBla
So, I would like to know can I import/add/include in my new TestPlan these test fragments and disabled/enabled specific HTTP requests. It will give me the ability to create different test suites.
The only option I can think of is using an Include Controller per API endpoint and naming them according to the endpoint URL.
Once done you can put them under the Switch Controller and choose which one you want to execute by providing the relevant "Switch Value"
The "Switch value" doesn't have to be hard-coded, you can use a JMeter Variable there originating from i.e. CSV Data Set Config

JMeter how to select randomely from a extracted set of values

I have a requirement to use randome url from a url list I extract from a json response.
Say I extract them in this mannser
imageUrls_1=https://blah01.com
imageUrls_2=https://blah02.com
imageUrls_3=https://blah03.com
imageUrls_4=https://blah04.com
imageURLs_matchNr=4
In a following JSSR223 sampler I was able to generate a variable called "url" with one of the url names selected randomely
("imageUrls_1","imageUrls_2",etc)
I was thinking to use them in my HTTP request to get the correcponding url as follows. ${${url}}. But soon found out its not giving me anything other than "${${url}}" :(.
JMeter Is it possible to place a varibale inside a varible name?
Basically I need to use one of the extracted urls randomely in my HTTP request.
The easiest way is going for __V() and __Random() functions combination like:
${__V(imageUrls_${__Random(1,${imageURLs_matchNr},)},)}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables
Use __V function
${__V(url)}
The V (variable) function returns the result of evaluating a variable name expression.

Get the path of an HTTP Request from another component

I am trying to let JMeter crowl my website to ensure a realistic stress test. I was able to extract the URLs from the home page and iterate on them. So I have a regular expression feeding a ForEach loop.
Now I am not able to let an HTTP Request take the output of the loop (Defined as a variable with a name) as its path.
Is there a general approach to setting the path of such a request. JMeter is taking something like:
${MyVar}
set in the path of the request as a string and is not replacing it with the actual value.
Given your Regular Expression Extractor and ForEach Controller configurations are correct everything should work fine. If you need any assistance with this provide the following screenshots:
Regular Expression Extractor configuration
Debug PostProcessor or Debug Sampler output in the View Results Tree listener showing several generated JMeter Variables
ForEach Controller configuration
HTTP Request sampler configuration (i.e. where do you put the variable)
Be aware that you can mimic crawling the site more easily using HTML Link Parser the relevant configuration would be as simple as
See How to Spider a Site with JMeter - A Tutorial to learn more about simulating websites crawling.

JMeter: how to vary request inside Thread Group

I have to write load tests for web application using JMeter. The application has items available for booking, each item has a 'Book' button. If some user clicks this button for item, it becomes unavailable for other users. My question is:
Is it possible to make JMeter threads to book different items (to make different requests) and how to implement it?
You should be able to determine what parameter is being posted by different "Book" buttons and modify nested requests as needed. Test plan structure should be something like:
Open Booking Page - HTTP Request
Get all Booking IDs - Post Processor
Book - HTTP Request
Where "Post Processor" can be
Regular Expression Extractor
CSS/JQuery Extractor
XPath Extractor
In case of multiple matches Post Processor will return multiple variables like
BookindID_1=some value
BookindID_2=some other value
BookindID_3=some other value 2
....
BookindID_matchNr=10
There are at least 2 options on how to proceed with these values:
Iterate all the values using ForEach Controller
Stick to current virtual thread number via __threadNum function so thread #1 will take BookindID_1 variable, thread #2 - BookingID_2 variable value, etc.
It is also possible to take random value using __Random function but it may result in request failure if item is not available.
The correct way of 2 variables combination looks like:
${__V(VAR1${VAR2})}
So combining BookingID_N and __threadNum will look like
${__V(BookingID_${__threadNum})}
See How to use JMeter Functions post series for more on what can be done via functions.
yes, If every item has static(predefined) unique id,descriptor,identifier then that can be parameterized using a csv config file or random no. generator and selector
Random no generator and selector will work only for integers but csv config is better/standard practice. If you need more help please paste your test plan here with explaination of your need.

Resources