Validate token without login multiple times - jmeter

In my script I am performing two steps,
Step 1: Login to the application
Step 2: Validate the coupon code from the CSV file.
Problem Statement: When I enter the coupon code on the URL it return me the following value, I want if the coupon code return me invalid then it should validate the next coupon code without switching back to login again.
{"Valid"} for Valid Token Code
{"InValid"} for Invalid Token Code
Test Plan:
CSV File:

Move your CSV Data Set Config to be a child of the Validate Coupon Code request. Amend Sharing Mode settings according to your test scenario
Put your Generate Bearer Token under the Once Only Controller, this way it will be executed only once per thread (virtual user), during the first iteration of the Thread Group and will be skipped for the subsequent iterations

Related

Rerun getToken(authorization) requests only on expiry - Jmeter

My testplan is as follows:
get token: requests to get access token
Setting a user defined variable to get the tokenGeneratedTime, let's say tokenGeneratedTime to ${__time(,)}
Check if token is expired(if controller) - {__jexl3((${__time(,)} - ${tokenGenerationTime}) > 3599000)}
if true, goes to get token sampler
if false, goes to subsequent requests
Some https requests
So if I run this test plan for the first time(only 1 iteration), request to get token is fired, the condition would be evaluated as false and the subsequent requests are fired. All is well and good. But as you can see, if I run the test plan again immediately(not iterating) for the second time, the get token(authorization) requests are fired again, which is not needed. I need to call the get token requests, only on expiry.
I'm thinking of setting a variable to false, if the token is not expired and putting the get token requests under an if controller. But how do I set a variable in if controller?
If you have any other ways of achieving this, please do suggest.
TIA
Use a flag to check the token expiry. e.g. isTokenExpired
Define the variable in the User Defiled Variables section and set the value to true. This will ensure token request is fired for the first time.
Add an IF Controller to the token request and check the condition ${tokenExpired}. Set the flag to false when a token is created successfully. vars.put("tokenExpired","false")
Add a JSR223 Postprocessor to the top level and check the response code 401 for the token expiry response. If the token is expired, set the flag isTokenExpired to true and redirect the thread to the next iteration immediately ctx.setTestLogicalAction(org.apache.jmeter.threads.JMeterContext.TestLogicalAction.START_NEXT_ITERATION_OF_THREAD .
String responseCode=prev.getResponseCode()
if (responseCode.equals("401")) {
log.info("Token is expired ")
vars.put("tokenExpired","true")
ctx.setTestLogicalAction(org.apache.jmeter.threads.JMeterContext.TestLogicalAction.START_NEXT_ITERATION_OF_THREAD )
}
if I run the test plan again immediately(not iterating)
If you run the test plan 2nd time it means that your tokenGenerationTime variable gets a new value of the current timestamp equal to the start time of 2nd execution.
If you want to be able to run your test plan 2nd time within 1 hour without firing the token generation request you can consider writing the tokenGenerationTime into a file using i.e. __StringToFile() function and read it from the file on 2nd and other test executions using __FileToString() function or if your logic is more complex you can go for __groovy() function and implement whatever you want there
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

Value cannot be null: Parameter: Source error received from JMeter

I have been receiving this error message on particular request - "Value cannot be null. Parameter name: source".
My Scenario is that 1 user will be transacting 5 transaction (Search and Remit). I'm targeting to run 650 Users to 3250 Transaction. The problem is that one particular request which is getting details from the DB, some data is passed but mostly are the mentioned error message above.
I Have 2 CSV Config, 1 from Users, the 2nd is for the Data where the second csv is inside the Loop Controller.
Your application tells you that the request is not correct, it expects a value and you're failing to provide the value. Use Debug Sampler and View Results Tree listener combination to validate the values of the JMeter Variables which are being sent for successful and not successful requests, it might be a test data issue, for example an extra comma in the CSV file will make CSV Data Set config "think" that this is the delimiter for the next column.

How to conditionally exit in jmeter

I have few steps in my script. I am testing it for 1000 users.
1. Validate username
2. Validate Password
3. User Info
4. Settings
5. Payments
20. Logout
etc...
I would get a token on password call, if call is success and then I would extract token run all the steps..
But If this is failed, then I don't want run all the step on the thread because it will definitely fail. It should go to step 1 again rather than running all the steps.
Consider put your steps until token created inside While Controller
The While Controller runs its children until the condition is "false".
As a controller Condition field you can check last sampler failed (assert that token is extracted)
${JMeterThread.last_sample_ok}
And it will loop until token retrieve and continue flow

How can run JMeter with limited CSV login details for multiple threads ?

Im just trying to run my JMeter script for 20 threads. I'm use CSV data set config for read login data. I set there are only 5 login details in CSV file. When i run the script only first 5 request got pass and rest of the thread request got fail. Anyone can suggest a solution. Thanks.
Apply the following configuration to your CSV Data Set Config:
Recycle on EOF - True
Stop thread on EOF - False
When JMeter reaches the end of the CSV file it will start over so 6th thread will get <EOF> as the value, 7th thread will pick 1st line, 8th thread will pick 2nd line, etc.
You can put your login request under the IF Controller and use the following condition:
"${line}" != "<EOF>"
to avoid the login failure due to this <EOF> variable value.

without using only once controller,i want the login request to be executed once

I am trying to do the load testing of the pages which can be access after login only.
As I am using Once Only Controller for login request ,when I changed Number of thread- 5 or more,login executes 5 times.
as Once Only Controller works for loopcount so I used loopcount but it slowdown my process and it executes the whole testplan.
My test-plan is:
login thread A- one time execution - how to do it?
http request B- multiple times(by using Number of threads)
http request C- multiple times(by using Number of threads)
What should I use for one time login execution and other successor requests needs to be executed multiple times without using Once Only Controller?
Kindly follow these steps:-
In Thread Group put number of threads:5 , Ramp-up:0 , Loop count: 1
Put your Login part in Once only controller
Right click on Your thread group > add > logic controller > loop controller
Now put your http request part in loop controller and set loop count of loop controller how many times you want to run
Then run the test you will get whatever you want
The Loop count in "Thread Group" is your full script Loop count not for your Transactions, for your transactions you have to put separate loop count before transaction starts.
Please do below
Your thread group setting should be below:
A.Number of threads :1
B:Ramp up period : 0 or as per application response.
C:Loop Count :5
Put your login request under Only once controller.
Request B and Request C should be at thread group Level.ie one step above it.
Run the request.
please find Sample Jmxsample Jmx for your reference Plse try. Hope it resolves your issue.

Resources