# How to get token from chrome local storage and store it in global variable?

**URL:** <https://forum.katalon.com/t/how-to-get-token-from-chrome-local-storage-and-store-it-in-global-variable/33796>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [September 26, 2019, 11:09am UTC](https://forum.katalon.com/t/how-to-get-token-from-chrome-local-storage-and-store-it-in-global-variable/33796 "2019-09-26T11:09:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spaceshadow1983](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@spaceshadow1983](https://forum.katalon.com/u/spaceshadow1983)\
**Post date:** [September 26, 2019, 11:09am UTC](https://forum.katalon.com/t/how-to-get-token-from-chrome-local-storage-and-store-it-in-global-variable/33796/1 "2019-09-26T11:09:40Z")

</div>

Hi, i am trying to retrieve token value from chrome local storage but i am not sure if i am using the right code.  
Could you please assist.

![image](https://europe1.discourse-cdn.com/katalon/original/2X/b/bf5fd9e24b6e20beb8ea5f35ec6f01de320d91ef.png)  
the value is adal.idtoken and i need to get the key/token from that value

This is the code that i am trying to use to get the value.

1. String bearerToken = WebUI.executeJavaScript(“localStorage.getItem(‘adal.idtoken’)”, null)  
Script is executed but no value is retrieved (as i can see in debug mode)

2. Then i am trying to store it in global variable:  
GlobalVariable.bearerToken = bearerToken

---

<div class="post-metadata">

**Author:** ![spaceshadow1983](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@spaceshadow1983](https://forum.katalon.com/u/spaceshadow1983)\
**Post date:** [October 2, 2019, 1:37pm UTC](https://forum.katalon.com/t/how-to-get-token-from-chrome-local-storage-and-store-it-in-global-variable/33796/2 "2019-10-02T13:37:43Z")

</div>

The correct syntax for retrieving adal token is:

def bearerToken = “”

bearerToken= WebUI.executeJavaScript(“return localStorage.getItem(‘adal.idtoken’)”, null)

---

<div class="post-metadata">

**Author:** ![albert.vu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/albert.vu/32/20595_2.png) [@albert.vu](https://forum.katalon.com/u/albert.vu)\
**Post date:** [August 8, 2022, 7:39am UTC](https://forum.katalon.com/t/how-to-get-token-from-chrome-local-storage-and-store-it-in-global-variable/33796/3 "2022-08-08T07:39:40Z")

</div>


