HTML Reports in JMeter - Modification - jmeter

I have a requirement in JMeter, While generating HTML reports using non gui mode,
Only corresponding controllers should get displayed and it should not display its HTTP request samplers
Controllers should not display randomly, It should display according to its order assigned inside the thread group (Eg: Controller 1, 2, 3)
Is there any solution for this requirement ?

To avoid displaying HTTP Requests, use Transaction Controller and apply naming policy as explained here.
For order, by default jmeter order by label. So an option would be to use a prefix that will be use for sorting (a, b, c ... z).

If you don't want the individual HTTP Request samplers to be displayed - put them under the Transaction Controller and tick Generate parent sample box
Add the next line to user.properties file:
jmeter.save.saveservice.subresults=false
Use __threadGroupName() function as the Transaction Controller's label prefix
Example test plan outline:
Example generated APDEX table in the dashboard:

Related

Consolidate JMeter SampleResult Entries

I'm making an HTTP Request where a component of the path is dynamic, resulting in unique Sample Results.
For example:
example.com/UNIQUE_ID
The UNIQUE_ID will change upon every request and create a unique request label like in the picture below:
Is there a way to consolidate them under a single entry?
You can use a JSR223 PostProcessor with following code:
String oldLabel = prev.getSampleLabel();
if(oldLabel.startsWith("example.com/")) {
prev.setSampleLabel("MyUniqueSample");
}
And scope it this way:
Just put your request(s) under a Transaction Controller and tick Generate parent sample box - dynamic names will be stored by the Transaction Controller's name.
If you're using JMeter 5.0 you will also need to add the next line to user.properties file:
jmeter.save.saveservice.subresults=false

how to run multiple urls in jmeter and it should display on one screen

i am new to jmeter. i would like to run multiple urls at one shot and display the results on one screen. finding hard to config urls through csv file and in jmeter.
my sample url:
http://10.56.34.67:7065/services/sample/2070
http://10.56.34.67:7065/services/sample1/2070
http://10.56.34.67:7065/services/sample2/2070
like this i have more thn 100 url to test it.
could you please tell me the format to store urls in csv file and how to config the csv file in jmeter?
It has simple as
Click Ctrl+0,Ctrl+1 which adds Thread Group and HTTP Request in side
In HTTP Request add ${path} to Path field
In Thread Group choose Loop Count Forever
Add CSV Data Set Config by right click on Thread Group -> Add -> Config Element
CSV Data Set Config parameters :
a. Put the fileanme in Fileanme field
b. Enter in Variable Names path
c. Choose Recycle as False
d. Choose Stop Thread as True
Click Ctrl+R (run)
It will go through all URLs and submit them sequentially
To view results you can add View Results Tree (Click Ctrl+9) and you will see all your requests/responses.
It seems your data here is your URLs.
So instead of using multiple samplers for each URL, you can go for CSV Data config and store all your URLs there and name the column as URL.
you can refer to this in your single http sampler as ${URL}.
Your CSV should look like this
In Server name put ${URL} and in the Thread Group check the forever check box
You don't need CSV for this use case, the easiest way would be going for __StringFromFile() function.
In the HTTP Request sampler put the __StringFromFile() function into "Path" input field like:
The textual function representation is ${__StringFromFile(urls.txt)}, you will need to replace urls.txt with full or relative path to the file where your URLs are listed
That's it, each time the request is called JMeter will read the next line from the file and substitute request path with the string from file:
See Apache JMeter Functions - An Introduction article to get familiarized with JMeter Functions concept

How to validate JMeter user defined variables?

I'm new to JMeter, I want to validate a JMeter test input variables defined as part of "User Defined Parameters". Let's say I have a variable "sessions" and my tester should pass input values in between 0 to 30 for sessions, if tester passes other than this range the test should not go further and should throw an error with appropriate message.
Is it possible with any kind of JMeter controllers/assertions/... without writing code for validation?
I am not sure is there any efficient/direct way of doing this. but I achieved your requirement as follows:
Add Setup Thread Group (before any other ThreadGroup). select radio button Stop Test Now in Action to be taken after a Sample error
Add Debug Sampler to the Setup Thread Group.
Add Response Assertion (RA) to the Debug Sampler.
In RA, Select JMeter Variable in Apply to section.
In RA, select Matches in Pattern Matching Rules section.
In RA, add the regex ^[0-9]$|^0[1-9]$|^1[0-9]$|^2[0-9]$|^30$ in Pattern to test text area.
Test will be stopped if you provide sessions value other than 0-30 in User Defined Variables, as Setup Thread Group is configured to Stop Test Now on Sample error.
Note1: Added View Results Tree Listener for confirmation whether the test is continued and also to check the error message. View Results Tree is added only for visual confirmation, must be removed during the load test, does not effect the actual logic.
Note2: I am not aware of any component, which can show custom message/alert to the user. so, used View Results Tree. We should remove this command during load testing. I added here for visual confirmation purpose. If not present also, Test will be stopped on wrong value for sessions, i.e., other than 0-30
Note3: We need a Sampler component in order to apply an Assertion. so, added Debug Sampler. Debug Sampler just reports all the JMeter variable values at the point of its execution.
Image references:
Setup Thread Group:
Response Assertion:
View Results Tree:
You cannot achieve such validation in GUI without amending JMeter source code but you can check the variable range using scripting.
For example, add a JSR223 Sampler as a child of the first request and put the following code into "Script" area:
import org.apache.commons.lang3.Range;
int sessions = Integer.parseInt(vars.get("sessions"));
String errorMessage = "Provided sessions number is not between 1 and 30, stopping test";
if (!Range.between(1, 30).contains(sessions)) {
log.info(errorMessage);
SampleResult.setSuccessful(false);
SampleResult.setResponseMessage(errorMessage);
SampleResult.setStopTest(true);
}
Demo:
Make sure you are using Groovy as a language (the option should be default as per JMeter 3.1, if you are using earlier JMeter version for some reason - you will have to choose groovy from the "Language" dropdown)

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.

JMeter : how to use the timestamp of the parent

I'm testing a group of urls for performance tests. We have an SLA that states that a certain group of URLS must have an average of 80% success within a certain timerange.
The logic of the sla is done in a separate application. The data is fed from JMeter output into a database.
I need a way to identify the 5 tests of these urls, so that the application knows they belong to the same test. I use a Transaction Controller to group all the URL tests, but I still don't see how I can put an identifier in the generated output file (done by View Results Tree Listener). If I could reuse the timestamp of the parent, i.e. the Transaction Controller for the individual HTTP Requests, that would make my day. I tried adding User Defined Variables under the Transaction Controller, but I don't see how I can output the value of my variable into the output file.
Is anything similar possible?
Best regards,
Wim
Store your value in jmeter context using a Beanshell sampler then in jeter.properties uncomment sample_variables ans add the name under which you stored your value:
Optional list of JMeter variable names whose values are to be saved in the result data files.
Use commas to separate the names. For example:
sample_variables=SESSION_ID,REFERENCE
Regards
Philippe M.

Resources