# Session variables handling

**URL:** <https://community.gatling.io/t/session-variables-handling/7373>\
**Category:** Gatling (Open-Source)\
**Tags:** gatling-academy\
**Created:** [December 2, 2022, 9:55am UTC](https://community.gatling.io/t/session-variables-handling/7373 "2022-12-02T09:55:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![balaji](https://avatars.discourse-cdn.com/v4/letter/b/2bfe46/32.png) [@balaji](https://community.gatling.io/u/balaji)\
**Post date:** [December 2, 2022, 9:55am UTC](https://community.gatling.io/t/session-variables-handling/7373/1 "2022-12-02T09:55:49Z")

</div>

How do i refer a session variable from one scala file to another?

```auto
.exec(session => {
  val token = session("acmToken").as[String]
  val token2 = "Bearer " + token
  session.set("acmToken", token2)
})

```

I need to use acmToken variable in another class or store in scala variables

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [December 2, 2022, 10:14am UTC](https://community.gatling.io/t/session-variables-handling/7373/2 "2022-12-02T10:14:20Z")

</div>

Hi @balaji,

As you set `acmToken` in session, you can retrieve it in another step (even in another scala file) from session as well.

See [Session API - Getting Attributes](https://gatling.io/docs/gatling/reference/current/core/session/session_api/#getting-attributes).

As it’s stored in session, ensure that it is from the same virtual user (ie, in the same scenario).

Cheers!

---

<div class="post-metadata">

**Author:** ![balaji](https://avatars.discourse-cdn.com/v4/letter/b/2bfe46/32.png) [@balaji](https://community.gatling.io/u/balaji)\
**Post date:** [December 2, 2022, 10:39am UTC](https://community.gatling.io/t/session-variables-handling/7373/3 "2022-12-02T10:39:26Z")

</div>

can you please give some examples?  
I need to use or store this acmtoken value in another variable

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [December 2, 2022, 10:52am UTC](https://community.gatling.io/t/session-variables-handling/7373/4 "2022-12-02T10:52:56Z")

</div>

@GeMi provided some examples: [Case0009SessionValuesSimulation](https://github.com/gemiusz/gatling-examples-maven-java/blob/master/src/test/java/pl/gemiusz/Case0009SessionValuesSimulation.java)

Thanks @GeMi ❤

Cheers!

---

<div class="post-metadata">

**Author:** ![balaji](https://avatars.discourse-cdn.com/v4/letter/b/2bfe46/32.png) [@balaji](https://community.gatling.io/u/balaji)\
**Post date:** [December 2, 2022, 1:03pm UTC](https://community.gatling.io/t/session-variables-handling/7373/5 "2022-12-02T13:03:33Z")

</div>

this doesnt help me much as well. Its written in java  
Can you please help here.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/2X/b/b148e0742de35c6280726cabf3ecd3de2d320f63.png) [@system](https://community.gatling.io/u/system)\
**Post date:** [January 1, 2023, 3:03pm UTC](https://community.gatling.io/t/session-variables-handling/7373/7 "2023-01-01T15:03:13Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
