Skip to content
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

Variables Not Cleared Between Tests #3988

Open
kreuka opened this issue Jan 11, 2024 · 3 comments
Open

Variables Not Cleared Between Tests #3988

kreuka opened this issue Jan 11, 2024 · 3 comments

Comments

@kreuka
Copy link

kreuka commented Jan 11, 2024

Description of the bug/issue

I can reuse the usual const/let variable from test number 1, in test number 2the

Steps to reproduce

No response

Sample test

    @a
    Scenario: Set 'test' variable
        Given I set the "test" value to the test variable
        When I log the test variable

    @a
    Scenario: Log 'test' variable
        When I log the test variable

const {  Given } = require("@cucumber/cucumber")

let test

Given(/^I set the "(.*?)" value to the test variable$/, (value) => {
    test = value
})

Given(/^I log the test variable$/, () => {
    console.log(test)
})

Command to run

npx nightwatch ./test

Verbose Output

info: Running the Scenario: Set 'test' variable
..STEP 1: Given I set the "test" value to the t
est variable
.STEP 2: When I log the test variable
test

info: Running the Scenario: Log 'test' variable
..STEP 1: When I log the test variable
test

Nightwatch Configuration

No response

Nightwatch.js Version

3.3.2

Node Version

18.21.0

Browser

No response

Operating System

No response

Additional Information

No response

@garg3133
Copy link
Member

Well, that's just how JavaScript (or any programming language for that matter) works... since test is declared in global scope (in the context of the file), it will be accessible in all the functions declared or called in that file. And if one such function changes its value, it will be changed for all the functions that access it afterwards.

What you can do is reset the variable test manually at the end or start of each test, but the function to reset should be mentioned in the same file so that it can access the test variable.

@kreuka
Copy link
Author

kreuka commented Jan 11, 2024

@garg3133 But it worked in another way in the 2.2.3 version. It also seems to me that it violated the principle where each test should be completely independent

@garg3133
Copy link
Member

@kreuka we'll look into it in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants