-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
global variables usable in different js (test) files #1121
Comments
Cypress test files are just regular JavaScript files that can |
@bahmutov thanks I tried this before but it didnt work. I defined alertSeverities variable in commands.js file and when I used that variable in a js file I encountered with this error ... Also, i created a js file for storing my global variables and I indicated its name in index.js file as import './globalvariables' and then I defined alertSeverities variable in globalvariables.js file but when I ran the test it failed again. I dont understand why it is not working |
TL;DR - just use modules, not globals. Cypress is just JavaScript. All of the underlying principles about structuring files apply to Cypress as it would your own application files. In this case, you keep mentioning variables. Variables are things defined in a particular file and are never global. This means it's not possible for them to be shared. Variables are accessible based on the local scope in which they are defined. In order to make them global you have to attach them to a global object: We have recipes of this here: https://docs.cypress.io/examples/examples/recipes.html#Node-Modules |
Thank you very much for your answers. @brian-mann I want to inform you about an issue (if i'm right...) in the following address, Cypress.addParentCommand() {....} used in the command.js file but this is not used anymore, isnt it? cypress-example-recipes/examples/fundamentals__node-modules/cypress/support/commands.js Cypress.addParentCommand("login", function(email, password){ .......... |
is there a way to define variables in order to able to use them 'in different js (test) files'
The text was updated successfully, but these errors were encountered: