Azure Load Testing Series - Accessing bearer token in Jmeter between different thread groups using BeanShell Assertion

Series - azureloadtesting

Hey folks!, In this blog we will see how to pass bearer token dynamically between two different thread groups using bean shell assertions. We will continue with the same Mock API that we used in our previous blog


In order to cover the scenarios, I have used a mock API that exposes token endpoint and a dummy GET endpoint.


  • Now we can move our existing “Get access token” HTTP request to newly created thread group

https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dsak1pws9dqjhm37w234.png

  • Now we can set a property similar to global variables that can be referenced in other thread groups

https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dheialdmmr3and7dghlz.png

  • In the script window type below command
1
props.put("access_token", vars.get("auth_token"));

https://dev-to-uploads.s3.amazonaws.com/uploads/articles/29iducfluuecuhez6g19.png

  • Now we can add a pre processor in the other thread group where we wanted to consume the auth_token by right clicking on ThreadGroup->Add->PreProcessors->BeanShell PreProcessor

https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ph49pjg1l4ooeznmfhee.png

  • In the script window type below command
1
2
String auth_token = props.get("access_token");
vars.put("auth_token", auth_token);

https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6hsdsegs8heci54bbzkb.png

  • Now click on Run , you will be able to see bearer token is passed as expected

https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6yd8qbvttp37t0wy3kxa.png


In our next blog we will see how to create test plan in Azure portal


Please go ahead and join our discord channel (https://discord.gg/8Cs82yNS) to give some valuable feedbacks