Variable Issue
# i-need-help
p
Hello! I'm quite new to Cypress, but I'm working hard to learn! I'm trying to build out tests for APIs, but am getting stuck at getting the authorize token into the test from my custom command. I am able to see it in the alias I created, but the variable on the actual test says it isn't defined. Would someone please show me what's wrong? I'm so interested in learning and am frustrated at getting stuck on this! I covered up some confidential things in the screenshots, but I don't think it will hinder people from seeing the code . The first screenshot is the custom command and the second is the test.

https://cdn.discordapp.com/attachments/1111120414022832158/1111122195641553016/image.png

https://cdn.discordapp.com/attachments/1111120414022832158/1111122195951923261/image.png

d
token is local variable, so it will not be accessible outside of command. you should try to use environment variables https://docs.cypress.io/guides/guides/environment-variables
p
Thank you! I will try this out!
h
You need defined token as global variable using setter and getter in test https://docs.cypress.io/api/commands/task#Save-a-variable-across-non-same-origin-URL-visits
g
Use cypress-data-session plug-in to init that token and access it via context property or Alia’s