How to run Authentication Thread every 4 min in Jmeter - jmeter

I have a jmeter test plan below
I need to run the login request every 4 minutes in order to get the bearer token. I have added the login request and a flow Control action in a thread with three threads (expected to be run three times every 4 min) and a main thread to call the services. I have used property value to transfer the bearer variable to other threads.
However, the login is running 3 times when the run started and services are failing after 4 minutes as the token request is already completed.
Can some one help here to run the login service every 4 minutes for the other services to get the bearer token

Make sure that the Thread Group is configured to have 1 thread (virtual user) and loop forever
You can ensure that the Login Request gets executed each 4 minutes using i.e. View Results in Table listener
The token can be passed to the ILS Service Thread Group via __setProperty() function and read via __P() function

Related

Jmeter- I have scenario where Users login once and does various transactions multiple times in a thread

Jmeter -->I need to do load test a scenario with 10 different users should login only once and other transactions should be done for multiple times ( might be using Thread) . And the 10 Authorization of all users should be used in other transactions.
I tried "IF controller" with code "${__groovy(ctx.getThreadNum() == 0 && vars.getIteration() == 1,)}" but authorization is used only once in other transactions
Once only controller also used -- Not working .. I think i am missing some logic here.
JmeterScreenshot_Scenario
Given your current implementation only 1st user will be logged in, others will skip the login request
Given you have 200 threads (virtual users) each of them needs to be logged in, authentication context is local to the thread (virtual user)
So if you plan to authenticate only 10 users, remaining 190 will not be authenticated hence all Transaction Controller children will be failing.
A good solution would be requesting more credentials so each of 200 users could have it's own username/password combination.
If a single user can be logged in only once and it's not possible to have more credentials, as a workaround you can authenticate 10 users somewhere in the setUp Thread Group and then pass the authentication context (cookies, tokens, whatever) to the main Thread Group via __setProperty() function or Inter-Thread Communication Plugin

OAuth token generation using Jmeter for multiple User-Credentials

I am testing an application hosted in gcloud, to execute the test using jmeter I require OAuth token for respective User credentials. I am able to generate the token for one credentials, however I have not been able to find a way to generate them for more than one users.
If anyone has faced such problem or has any glimpse please let me know.
Note:
I need a fresh token with every iteration since token expires in every 60 mins
I am able to generate token manually to run the test
I have tried auth/header manager for the process
I have tried console auth code generation code as well
Above all generate auth code for a specific credential, wherein I have to keep the application active.
So you want to apply load to app backend using authenticated users.
If so, why don't you use
CSV File to store your test credentials
Use JMeter's CSV Config to read those credentials
once only controller for authentication, extract access_token and refresh_token
Use tokens to make calls to your backend
If you need to run loadtest / soak test for longer than one hour you can use if controller to verify the token validity and renew the token if necessary.
Hope this helps.
If you need to refresh the token each 60 minutes it makes sense to create a separate Thread Group which will be executing a token refresh request each 60 minutes.
The token can be passed to the main Thread Group using __setProperty() function, you can make the token value thread-specific by combining it with __threadNum() function like:
In "token" thread group:
${__setProperty(token_${__threadNum},${token},)}
In "main" thread group you can read the value using __P() function:
${__P(token_${__threadNum},)}
Demo:
More information: Knit One Pearl Two: How to Use Variables in Different Thread Groups

How can i simulate just one login for all thread groups?

I have just started working with Jmeter (5.1.1) and i have multiple thread groups.
In every thread group, i have to add the login http request or else the tests will fail.
How can i simulate just one login request for all the thread groups ?
Thanks in advance.
You can add a setUp Thread Group in order to execute the login, setUp Thread Group should be used for preparing test data, if you really want to use the same context coming from a single login from all virtual users in all thread groups (this makes sense only if you're using JMeter for a functional test) you can perform the login only once there.
Once you perform the successful login you should pass the associated indicator of the login (most probably it will be Cookies or other HTTP Headers) to other Thread Groups, the value(s) can be set using __setProperty() function in the setUp Thread Group and read using __P() function in other Thread Groups

How to regenerate token in JMeter at fix interval time

I am doing API Performance Testing for my application. I am creating a script using JMeter. Now, I am facing the issue that on our application auth_token is only valid for an hour. After that it becomes invalid and we need to generate new token. So how can I manage this mechanism in JMeter where I can regenrate token after fixed interval?
You and create a separate Thread Group where you will have i.e. Test Action sampler configured to "sleep" for 1 hour and the logic to "regenerate" the token.
So you will have 2 Thread Groups:
"Normal" one where your API testing happens
"Another" one where a new token will be generated each hour
You can pass the token from "Another" to "Normal" thread group using __setProperty() function

login with two different users for different use in jmeter?

How can generate following scenario,
user1 logged in & take some action on form.
user2 logged in & approve the taken action.
please suggest best way to automate the scenario via jmeter.
Depending on what you are trying to achieve:
Easy way: single Thread Group. Just add one HTTP Request sampler per each action, i.e.:
HTTP Request 1 - login 1st user
HTTP Request 2 - perform an action
HTTP Request 3 - logout 1st user
HTTP Request 4 - login 2nd user
HTTP Request 5 - approve the action
etc.
If you have 2 Thread Groups, i.e. first one is creating the actions and the other one is approving them the best option to ensure that the the "approvers" have something to approve will be using Inter-Thread Communication plugin, this way you will be able to "pause" the approvers until approval forms get created. You can install Inter-Thread Communication plugin (as well as the other plugins) using JMeter Plugins Manager

Resources