I have three APIs:
Create a user (returns userId in response body)
Add photo corresponding to user created in step 1 (takes userId in request body - same as obtained in response of first body)
Poll the API to check whether user photo updation is done (takes userId in request body - same as obtained in response of first body)
Running of these three APIs constitutes one logical flow of the application.
I want to run and benchmark this 'set' of three APIs.
I have following concerns in this regard:
How should I decide whether to have three different thread groups to run these 3 APIs or a single thread group should suffice ?
What should be used to extract 'userID' from first API response and use it as an input to second request.
How can I implement polling mechanism as needed in third API ?
If I have say 5 users hitting request1 and then the same 5 users hitting request 2, how can I establish mapping between requests so that user1 by first API gets mapped to second API ?
How should I decide whether to have three different thread groups to run these 3 APIs or a single thread group should suffice ? - I would go for a single Thread Group as it assumes actions of a single virtual user (or a group of virtual users)
What should be used to extract 'userID' from first API response and use it as an input to second request. - depending on the response type, JSON Extractor for JSON, XPath Extractor for XML
How can I implement polling mechanism as needed in third API ? - using While Controller
If I have say 5 users hitting request1 and then the same 5 users hitting request 2, how can I establish mapping between requests so that user1 by first API gets mapped to second API ? - you don't need to do anything, each JMeter thread (virtual user) executes samplers upside down and all the context like variables is local to this user (thread)
Related
I have multiple Simple Controllers under Thread group. All controllers have 1 HTTP request. Only one controller have 3 requests. How can I chain 3 requests in one simple controller to run sequentially.
Test Plan
The screenshot above is my test plan. In v4/bootstrap call I have 3 HTTP requests. Result of these 3 requests is token which I extract from get_v4/restart and then this token used for all other requests. For correct token generation 3 requests from v4/bootstrap call should run sequently. On summary report shown that amount of run 3 requests is different.
Each JMeter thread (virtual user) executes Samplers upside down. The same applies to Simple Controllers.
So you don't need to do literally anything, each thread will execute samplers sequentially as they appear in the Test Plan.
If you have more than 1 virtual user in the Thread Group you might be confused by the "wrong" order of sample results:
However each user is still executing samplers upside down, you can check it by adding __threadNum() function to show the current virtual user's number and __groovy() function calling vars.getIteration() method
You will see that each user executes samplers sequentially and starts over when the last sampler ends and there are iterations still:
I want to develop JMeter 5 test plan with the following spec:
First call HTTP Rest API A. if the status code from A is not 200, keep repeatedly calling A until status code is 200. After first successful call to A, then proceed to call Rest API B.
There is CSV Data Set Config for API B which reads CSV file, each entry in CSV invokes a call to API B. When EOF is reached, JMeter must automatically exit (stop running).
API A must be called once every 10 minutes while API B is still being called (or JMeter is still running processing CSV file).
How to achieve this goal? 2 Thread groups are required or single thread group can do the job?
Please provide details like what should be the configs for test plan and thread group(s), the sequence of JMeter elements like While Controller, etc.
The purpose of the test plan is load testing API B, so multiple threads may call API B while a single thread is used to call API A.
You will need 2 Thread Groups in order to run requests against API A and API B with different number of users and concurrency
In order to repeat request to API A until response status code is 200:
Add a While Controller and use the following __groovy() function as the condition:
${__groovy((vars.get('code') ?: 42) as int != 200,)}
Add your HTTP Request for API A as a child of the While Controller
Add Boundary Extractor as a child of the HTTP Request and configure it like:
Add Flow Control Action sampler and configure it to sleep for 600000 milliseconds either inside the While loop or outside depending on your scenario
With regards to to stopping the test when the end of CSV file is reached it's just a matter of setting the next parameters in the CSV Data Set Config:
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
I am trying to run http samplers sequentially for multiple requests. Where the output of 1 API response is the input of next API request. My concern is when I run with 5 users (for. e.g), then at given point of time it first executes 1st API with 5 users then second API with 5 users, in this process the API where input is required gets lost. Please help me on this.Actually I have used transaction controller also but here not sequentially api run,so getting file not found exception bcause of first api output response parameter is not passed to second api as a input parameter
I need a solution, where all the samplers are first executed for first user, then for second thread all the samplers are executed and so on.
Each JMeter Thread (virtual user) executes Samplers upside down, if you have 2 samplers each user will always run 1st sampler then it will run 2nd sampler.
You can use __threadNum() function and ${__jm__Thread Group__idx} pre-defined variable in order to verify that the execution order is sequential.
If you want all the users to execute first sampler then all users to execute the second sampler - go for Synchronizing Timer
If you want to get to the reason of the failure try saving the responses using i.e. Simple Data Writer as it might be the case your "first" API fails silently and hence your correlation doesn't extract the value.
I have two separate thread groups in jmeter,
First Thread Group: All the Users corresponding to first thread group are responsible to hit an API which creates a user and return userId in response
Second Thread Group: All the Users corresponding to second thread group are responsible to hit an API which uploads photo for created users and uses userId (returned in previous response) as its request data.
I have used InterThreadCommunication plugin of jmeter and so userID from response of API hit of first thread group get mapped to request data of API hits of second thread group.
The problem is that in Thread Group 2, I need to run upload image of user 5 times (in order to have a set of images corresponding to each user). How can I extend InterThreadCommunication functionality to map one userId from threadGroup1 to 5 requests of threadGroup2 (and similarly another userId to another 5 requests)
Current Implementation:
Thread Group 1:
jp#gc - Inter-Thread Communication PostProcessor:
FIFO Queue Name to put Data in: userIdList
valueToPut: $userId
Thread Group 2:
jp#gc - Inter-Thread Communication PreProcessor
FIFO Queue Name to get Data from : userIdList
variable name to store Data: userId
Thread Group 2 request data , I am using value as $userId
Just get it once using Once Only Controller and execute the request 5 times using Loop Controller
If Inter-Thread Communication Plugin is not flexible enough to fit your needs you can always switch to another approach of passing the values between Thread Groups, i.e.
Use __setProperty() and __threadNum() functions combination to store the value in 1st Thread Group like:
${__setProperty(userid_${__threadNum}, YOUR_VALUE_HERE,)}
Use __P() and __threadNum() functions combination to read the value in 2nd Thread Group like:
${__P(userid_${__threadNum},)}
Check out Apache JMeter Functions - An Introduction article for more information on JMeter Functions concept.