Help with adding oAuth to request headers based on session value

Hey guys,
I’m new to gatling and Scala, so I apologize in advance if this is an obvious answer. We have a very complex system we’re testing, and I’m breaking down operations into objects that encapsulate the behaviors so that we can re-use them. We’re then re-using these behaviors by chaining the executions together in out test scenarios. I have the following basic steps.

  1. Register
  2. Login, which returns an oAuth token
  3. Create an application, using the oAuth token from 2 in the header.

I have 1 and 2 working, and my token stored in the session.

Here’s my file for 1)

Here’s my file for 2)

Here’s my file for 3, with the Headers utility object

What’s not clear to me is how to test the current session for the presence of the value “accessToken” and add it to the headers map. I may be doing this incorrectly as well. Is there a more conventional way for me to accomplish this?

Thanks in advance,


You can use Gatling EL for header value:
.header(“foo”, “${bar}”)

Hi Landelle,
Thanks for the help. I know I can use the el and if the value is present it will be out in the headers. However. We have some requests that are anonymous. We won’t have tokens and this will cause errors. I want to exclude the map entry completely if “authToken” is not present.


But then, aren’t anonymous and authenticated users 2 different populations/scenarios?
Why don’t use set up different headers/header maps?

Yeah, I figured that out right after I hit send. Kind of the point of using a declarative syntax. I’ve been using java for far too long…

Thanks again!