JMeter - Hitting specific endpoints based on user credentials via multiple CSV files - jmeter

My JMeter test:
Iterate over a CSV file (logins.csv) with login credentials, and their unique identifier user a CsvDataSetConfig
Sign in
Based on the login credentials (unique identifier from logins.csv), identify and load a second file in the format of <user_identifier>_invoices.csv which then has the necessary path to view an invoice for that user.
Simplified test setup:
ThreadGroup
> CsvDataSetConfig - file: logins.csv, variables: user_identifier,email,password, sharing_mode: all threads
> `SignIn` TransactionController using email and password from above CSV file to login via series of HTTP Requests
> UserParameters - USER_IDENTIFIER,INVOICE_CSV_FOR_USER
> BeanShellSampler
props.setProperty("USER_IDENTIFIER", vars.get("user_identifier"));
props.setProperty("INVOICE_CSV_FOR_USER","${__P(USER_IDENTIFIER)}_invoices.csv");
> WhileController - condition: ${__javaScript("${invoice-id}" != "<EOF>",)}
> CsvDataSetConfig - file: ${__P(INVOICE_CSV_FOR_USER,)}, variables: invoice-id, sharing_mode: current thread
> `ViewInvoice` TransactionController with HTTP Request to url `../${invoice-id}`
# logins.csv
c7beaa99c6d99fa7754fc2213f9b17b8,foo#example.com,password321
9c8466bee65e39c9d3cf715e42933c3b,bar#example.com,password456
# c7beaa99c6d99fa7754fc2213f9b17b8_invoices.csv
f54eca1cbbba4a97c1dc459e0ba64970
0024f2cdf28dd7ebf3606988fd229afd
# 9c8466bee65e39c9d3cf715e42933c3b_invoices.csv
64f725fdeb2980b28bdf5e02076a55cd
60ac45a12ea3d6b59c2cb82f27da1722
Problem:
In local JMeter, seeing requests to invoice urls being made with incorrect invoice-id for the business. So seems the parameters are not being treat correctly between threads.
In BlazeMeter, seeing the content of the while controller never being hit.
I've tried loop controllers, having 50 rows per _invoices.csv file, but not got anywhere with that either. I also originally started off with
User Defined Variables rather than User Parameters, but the latter seems to be what I should be using for this use case.

Threads are running at the same time and sharing JMeter properties.
In your test plan each thread sets the property USER_IDENTIFIER. So this and other property can/will be overriden by different thread(s) and create inconsistency.
I suggest you save (and get) in variables which aren't shared by threads:
vars.put("USER_IDENTIFIER", vars.get("user_identifier"));
vars.put("INVOICE_CSV_FOR_USER"," ${USER_IDENTIFIER}_invoices.csv");
Also about beanshell, JMeter advice to change to JSR223
Since JMeter 3.1, we advise switching from BeanShell to JSR223 Test Elements (see JSR223 section below for more details), and switching from __Beanshell function to __groovy function.

Related

Strange labels with suffix -0, -1 in jmeter results

We recently updated apache jmeter from v4.0 to the latest v5.4.3.
The tests are running fine, but we have strange results.
The requests appear with 3 different labels (without suffix or -0 / -1 appended).
timeStamp, label, responseCode, threadName
1643834640785, API call, 200, Load Group 1 1-1
1643834640785, API call-0, 302, Load Group 1 1-1
1643834641189, API call-1, 200, Load Group 1 1-1
1643834640785, API call, 200, Load Group 1 1-2
....
It seems to me this happens, when the same thread calls the API multiple times.
I am not a jmeter and I am not sure why this happens and how to fix it. Also I don't know what information is needed to analyze the problem correctly.
Thanks in advance!
I'm seeing HTTP Status 302 which means redirection (for example from HTTP to HTTPS or from global website to country-specific website), in that case JMeter generates additional Sub-Result.
The "strange" labels is how JMeter calculates throughput for embedded resources and the cumulative execution time of the parent sampler in case of redirects as well.
The question is what do you want to do with this.
The options are in:
Take it for granted given the above explanation
If you want the "strange" labels to be resolved into real URLs - tick "Functional Testing" box in the Test Plan
or add the next line to user.properties file:
subresults.disable_renaming=true
If you want to get rid of these subresults completely - add the next line to user.properties file:
jmeter.save.saveservice.subresults=false
More information:
Configuring JMeter
JMeter Properties Reference

How to share access token between JMeter thread groups

I have added the Test Plan in below-following orders
1.Test Plan with user defined variables
2.Header Manager
3.Thread Group 1
4.Http Request
5.JSON extractor
6.Thread Group 2
7.Http Request
8.BeanShell Preprocessor
9.Result Tree
Screenshot
How to pass the access token(s) from the first thread group to the second thread group?
Variables cannot be passed/shared between the thread groups.
There could be a number of solutions.
Option 1
Use JMeter properties to share the access token between the thread groups.
props.put("accessToke", accessToke) to add the token and use props.get('accessToken') to retreive the values from the second thread group.
In this solution, you can share just one token across the thread groups.
Options 2
Using Inter Thread Communication plugin.
These queues work in First-In-First-Out manner. You can put a string
value into a queue from one thread, and then get that value from
another thread, even in another Thread Group.
There were at least 3 errors during your last test execution:
Check jmeter.log file for details, the reason should be there
You should be using different thread groups for representing different groups of business users, if you're simulating authentication flow it makes sense to keep both HTTP Request samplers under one Thread Group
JMeter Variables are local to the thread (virtual user) so you won't be able to access the variable value in the different thread and thread group
Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting
There is no need to go for scripting at all, just add a HTTP Header Manager as a child of the workspace request (see JMeter Scoping Rules - The Ultimate Guide article to learn more about the scope of JMeter Test Elements) and define the token there. Suggested Test Plan Structure:
Just finished figuring this out. Don't know if it's the best solution. Looked like there were other options.
In my case the first thread group was reading a list of users and passwords from a csv file.
I did it by writing a csv file in the first thread using "JSR223 PostProcessor" after each authentication API call.
Then I read the newly created csv using the "CSV Data Set Config" in the second thread.
Groovy script follows:
import org.apache.jmeter.services.FileServer
log.info("*************************************")
def userId = vars.get("user_id") //JMeter var from parsing auth request
def authToken= vars.get("auth_token")
def configDir = vars.get("config_dir")
log.info("userId:" + userId)
log.info("authToken:" + authToken)
def outputFilePath = configDir + "/userToken.csv"
File outputFile = new File(outputFilePath)
//check if the file exists
if (!outputFile.exists()) {
log.info("File " + outputFilePath + "does not exist")
log.info("Creating a new file")
outputFile << "userId,authToken\n"
}
outputFile << userId + "," + authToken + "\n"
Test Plan on JMeter

How to save 10 different id from Jmeter response and use it in next 10 requests

I am currently running 10 different threads like this:
each of the thread response will provide a different id in the response and i want to save them and use it as a request in the next test case(10 threads) so there will be 10 ids and 10 threads and each thread will have a unique id as a request. This is what I am doing:
Here is the first request
This is how I am extracting the values
This is how i am using the final request however i am not able to get the desired results
UPDATE:
I tried Dmitri Answer but still no luck i am extracting the id by using this
I used __threadNum() function as the prefix or postfix for the property name like:
${__setProperty(loginassistant_${__threadNum},${loginassistant_},)}
and read it similarly:
${__P(loginassistant_${__threadNum},)}
but it is not working and it is setting the value as a static string(see screenshot below):
This is how and where i am defining my loginassistant using the simple controller:
You're using properties which are global, if you have more than one thread the next thread will overwrite the property defined by the previous thread so it could be mismatch.
If you don't need to pass values across thread groups - go for JMeter Variables instead, variables are local to the thread (virtual user) and the properties are global for the whole JMeter/JVM instance
If you do need to pass values across thread groups - either use __threadNum() function as the prefix or postfix for the property name like:
${__setProperty(loginassistant_${__threadNum},${loginassistant},)}
and read it similarly:
${__P(loginassistant_${__threadNum},)}
or go for Inter-Thread Communication Plugin

How to Save all Responses to a file with loop count more that one?

This is a part of my test plan, and the loop count is 2.However only one set of responses generated
even i select "Add timestamp"
so, how to save data base on loop count ?
If you want to have separate files with the responses for each thread (virtual user) and Thread Group iteration you can use
__threadNum() function
${__jm__Thread Group__idx} pre-defined variable as prefix or postfix for the filename
So given the following configuration:
Here is the textual representation just in case:
user-${__threadNum}-loop-${__jm__Thread Group__idx}-response.txt
You will have the following files:
user-1-loop-0-response.txt
user-1-loop-1-response.txt
user-2-loop-0-response.txt
user-2-loop-1-response.txt
More information: Performance Testing: Upload and Download Scenarios with Apache JMeter

How to do load-testing for 100 concurrent users login with unique username and passwords using Jmeter?

My test plan scenario is to do load-testing for 100 concurrent users login to website.
I have created Threadgroup with Number of threads as 100.
Created CSV file which contains 100 users login details (unique usernames and passwords).
Under Sign in sample added a “User Parameter” from Thread Group -> PreProcessors to it. Added variables using __CSVRead function which reads values from file test.csv.
Selected the login sample and changed the values of userid and password to ${A} and ${B}.
Is this the right way to do or is there any alternative way to achieve this?
If this works for you and works as you expect, that's enough.
But looks like CSV Data Set Config is more suitable and easier to use for multi-user scenarios than __CSVRead function:
Thread Group
Number of Threads: N // count of your test-threads (users)
Loop Count: 1
CSV Data Set Config
Filename: [path to your csv-file with usernames / passwords]
Variable Names: username,pwd // extracted values can be referred as ${username}, ${pwd}
Recycle on EOF? False
Stop thread on EOF? True
Sharing mode: Current thread group
. . .
HTTP Request // your http call
. . .
As per documentation:
The function is not suitable for use with large files, as the entire
file is stored in memory. For larger files, use CSV Data Set Config
element or StringFromFile.
Pretty detailed guides available here:
How to use a CSV file with JMeter
Using CSV DATA SET CONFIG

Resources