# Azure Load Testing Series - Accessing bearer token in Jmeter between different thread groups using BeanShell Assertion ## About this blog 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 ------------------- ## Mock API In order to cover the scenarios, I have used a mock API that exposes token endpoint and a dummy GET endpoint. - Mock API - Mock Oauth Token endpoint ------------------- ## Extract token between two thread groups using BeanShell assertions ### Creating two thread groups - Now we can move our existing "Get access token" HTTP request to newly created thread group ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dsak1pws9dqjhm37w234.png) ### Create BeanShell assertion - Now we can set a property similar to global variables that can be referenced in other thread groups ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dheialdmmr3and7dghlz.png) - In the script window type below command ```cmd props.put("access_token", vars.get("auth_token")); ``` ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/29iducfluuecuhez6g19.png) ### Create BeanShell PreProcessor - 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 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ph49pjg1l4ooeznmfhee.png) - In the script window type below command ```cmd String auth_token = props.get("access_token"); vars.put("auth_token", auth_token); ``` ![Image description](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 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6yd8qbvttp37t0wy3kxa.png) ------------------- ## Next steps In our next blog we will see how to create test plan in Azure portal ------------------- ## Join us Please go ahead and join our discord channel (https://discord.gg/8Cs82yNS) to give some valuable feedbacks ## Sponsor