JMeter how to load certain group of users - jmeter

I am loading a csv file with usernames and passwords of users.
Each user belongs to a certain group eg. Group1_user1, Group1_user2,.... Group7_user1, Group7_user2 etc.
I have recorded with my Script Recorder in JMeter the HTTP requests for log in of all the users and then the steps of a HTML stepper process.
Only one group has the permission to complete a step.. there is an hierachy in the groups.
So, my question is.. since I am loading all the users, how am I going to test each step for the users who belong only to the right group?
I cant use plug-in and I cant break my Test Plan into smaller Test Plans.

Normally you should be using different Thread Groups for representing different groups of logical users, so I would suggest moving at least those guys who have permission to complete a step into a separate thread group.
You can implement synchronization and passing data between thread groups if needed using Inter-Thread Communication Plugin
If you have to stay with the single Thread Group you can use If Controller or Switch Controller to conditionally decide which step can be taken by which user.
For example if you use the following __jexl3() function as the If Controller's condition:
${__jexl3("${username}".contains("Group1"),)}
then If Controllers child(ren) will be executed only if ${username} variable will contain Group1
Demo:

Related

Jmeter - How to pass multiple tokens from http login request to another http request

I am currently designing a test case for multiple users testing using jmeter and I kind of need some help.
Here's the scenario:
Suppose I have 2 different login portals with 500 different users on each portal. I want to do login, access getExamSchedule, startExam, getListQuestion, getOneQuestion, submitOneQuestion and finishExam so I create one new thread group for each request. Each thread has 2 samplers (1 for portal A, 2 for portal B).
My question is how am I supposed to pass the multiple generated tokens from login thread so that I can access the rest of the thread with different tokens. And also each http request has some response I need to extract to be used on another thread. I tried to extract the tokens and the responses to csv file but somehow it didn't work. Let me know if there's any best practice for this scenario. Thank you in advance!
so I create one new thread group for each request - normally you should create separate/different Thread Groups only for new logical groups of virtual users, for your use case I think everything could be in one Thread Group.
As per JMeter Documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
So if you really need to pass values across different Thread Groups - you can take a look at following solutions:
__setProperty(), __threadNum() and __P() functions combination like:
To set the property:
${__setProperty(token_${__threadNum},${jmeter-variable-holding-the-token},)}
To read the property: ${__P(token_${__threadNum},)}
Use Inter-Thread Communication Plugin

Simulate Loadrunner like jmeter scenario with multiple functionalities (thread groups)

So, I have 7 functionalities as below for simplicity.
Create customer - 10
Search customer - 100
Delete Customer - 10
Edit Customer - 30
Open Account - 10
Search Account - 100
Delete Account - 10
Now I want to simulate all of the above functionalities together in one test plan. For all functionalities, I need to login only once and then once all users for all functionalities are logged in, continue the respective activities for a period of 1 hour.
What I tried:
Place each functionality in separate thread group. For each thread group, keep login and logout separately and all other actions in a runtime controller having a runtime of 3600 mS. This serves the purpose but the timer of all users will be different (based on the time they login) which does not allow all users to start their period of 1 hour simultaneously.
Use ultimate thread group for each functionality and put login and logout in separate once only controller (login at start of thread group and logout at end) and other actions in loop controller with loop count checked as infinite. This works fine but it did not execute the log out once only controller at the end of the test.
The aim of doing this is to achieve the concurrency of desired users and also to run with achieved concurrency for desired duration of time.
Any suggestions on how can I go about with achieving this?
I would suggest the following approach:
Put your "login" logic into the setUp Thread Group
Put your "logout" logic into the tearDown Thread Group
Distribute the load across your "7 functionalities" either by putting them into different Thread Groups or via Throughput Controllers
You can pass the user identity (cookie, token, whatever) using one of the following options:
Inter-Thread Communication Plugin
__setProperty() function in the setUp Thread Group to write the identity into a JMeter Property and __P() function in other thread groups to read the values. Of course you should add __threadNum() function as the property name prefix/postfix to distinguish the identities for different users

Running Jmeter Test in multiple accounts parallelly

I have set of sampler under one Thread Group as
TestPlan
ThreadGroup
SimpleController
Login(HTTP Sampler)
FetchCSRFToken(HTTP Sampler)
LoopController(Count -> 5)
Testcase1(HTTP Sampler)
Testcase2(HTTP Sampler)
Testcase3(HTTP Sampler)
Now I got a requirement to run the above test cases in multiple accounts parallelly.
I googled and find out having Multiple Thread Group is a better idea since I suppose to run it parallelly and I have to pass CSRF token in all test cases header.
Is it possible to have two thread groups without duplicating the test cases inside Loop Controller of Thread Group-1 to Thread Group-2?
Kindly suggest if any other way as well.
If you want to avoid code duplication - just put the "shared" code under a Test Fragment and reference it using Module Controller(s) where required
In general a Thread Group should represent a logical/business group of users, if you just need to add more users doing the same actions - you can parameterize credentials, URLs, parameters, etc. so each thread will use different set of data on each iteration, the most commonly used approach for parameterization is CSV Data Set Config

JMeter - reusing random variables in another thread group

I currently have a test plan where I use a random variable to submit a post request to a given URL (/app/${app_id}).
I want to also re-use the random variable app_id to poll the status of that app (/app/${app_id}/status). Note there would be multiple requests to the status URL.
My current idea is to:
have one thread group that submits the posts
save a list of the randomly generated app_ids
in another thread group, read the list of app_ids and for each app_id, loop the status request
Is this a sensible approach? If so, how can I go about saving the randomly generated app_ids and then reading them?
Also, if there is a better approach to this situation, I'm all ears :)
You can pass the values from one thread group to another one using __setProperty() function like:
${__setProperty(appid-${__counter(FALSE)},${your_variable_holding_appid},)}
Each time the function will be called it will generate a JMeter Property in form of
appid-1=foo
appid-2=bar
appid-3=baz
etc.
Where numbers like 1, 2, etc. are coming from __counter() function
In another Thread Group you will be able to access the generated values using __P() function like:
${__P(appid-${__counter(FALSE)},)}
Demo:
See Apache JMeter Functions - An Introduction for more information on JMeter Functions concept.
There is more "advanced" way of passing JMeter variables between threads and even thread groups, moreover you will be able to synchronise your threads, i.e. don't start thread in 2nd thread group until variable is not set using Inter-Thread Communication plugin.
Solution with Thread Groups is feasible, although you also can do all that in one thread group, by configuring one of the threads to be "monitor", while remaining threads submit posts. Something like this:
Thread Group
If [${__threadNum} == 1]
Samplers to check status
If [${__threadNum} != 1]
Samplers to submit posts
One reason to use 1 thread group for both types of users is if you need any sort of synchronization between writing and reading app_id list - that is easier to achieve in one thread group. Or if you already have many thread groups.
As for providing app_id to various threads/thread groups, you can use one of the approaches:
To pass IDs from one thread group to the other without a file, you can use one of the methods described here (using properties is the most popular way).
In your case, probably the easiest is to save them in one property with some delimiter, e.g. ID1,ID2,.... The "status" thread then can get this property, split it using either script or __split function to convert property into serialized variables: app_id_1, app_id_2, etc. Those variables are a natural choice for ForEach Controller.
Also first thread group could be saving app_ids into file, while the other reads from the same file with CSV Data Set Config. A bit of caution here though, if they are doing it at the same time.
If app-ids can be pre-generated, a more economical approach would be to have SetUp Thread, which generates them and saves them to CSV file (you will only need one script, e.g. BeanShell to do that, see example here). And then both thread groups read from that file using CSV Data Set Config

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