1
votes

I have a JMeter script which tests around 25 different REST API's (this is not a load test but API functional test). All these API's require an OAuth based access token which I generate at the start of the test and save in a variable which is then used by all the subsequent API calls.

The issue is that the expiry of a token is 10 mins and if the test exceeds that duration then rest of the calls fail with 401. Is there a way by which I can repeat the first call I made repeatedly after 5 mins so that a fresh access token is always available? Thanks.

enter image description here

Not sure of this image will help but the opentokenID call generates the access token followed by all other calls which use it. I want to know if there is some mechanism to re-execute opentokenId call in the middle of tests so as to get a new access token.

2
can u share ur script image. jmeter screen shot it is possible throug json extractor for extracting accesstoken dynamicallyprat22
I am extracting access token dynamically but it expires after 8 minutes and I need to figure out a way by which I can repeat the call say after every 5 mins while the rest of the test goes on unaffectedvaibhav misra
There are also other tools availabe for Functional Api Test [ApiTestingtools](joecolantonio.com/2017/05/16/…)prat22

2 Answers

1
votes

You want to re-execute the auth token request in middle and then use latest token for further requests. Now, you can achieve this as shown in the below plan:-

1.Simple controller with auth request.

  1. N number of multiple controller and requests.

  2. In between you can put "Module Controller" and select "Auth Token Simple Controller" or whatever controller you have for it.

Once your thread reach module controller it will re-execute the Auth token request and then continue further as shown below. Thought, it is not dependent on time but I think it will suffice your requirement. If you need you can add "module controller" at multiple places in your test plan.

enter image description here

1
votes

Here is what worked for me. I created a separate thread group and moved the auth token call to that group. Further, the expiration time of token was 10 minutes so i put a timer of 7 minutes and put that in a loop (actually a while controller which was checking for a value to become false to terminate). So every 7 minutes the thread group would execute the token call.

I was saving the token in a variable and passing it to the other thread group. This link will give you an idea of how to do it How do I pass a variable from one Thread Group to another in JMeter