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

Globals does not persist in parallel test runs even when persist_globals setting is enabled. #3987

Open
garg3133 opened this issue Jan 10, 2024 · 1 comment · May be fixed by #4148
Open

Comments

@garg3133
Copy link
Member

garg3133 commented Jan 10, 2024

Description of the bug/issue

The changes we make to browser.globals by default do not persist for the complete duration of the test run and are only available in the context of the test suite where the changes are made.

So, to allow users to have the changes made during the test run to persist till the end of the test run (even across test suites), we have persist_globals setting. And while this setting works great when running tests in serial mode, it is not obeyed in parallel mode.

Now, in parallel run, persisting changes to globals across test suites do not make any sense as the test suites will be running parallelly in different worker processes. But, if we make some changes to globals in the global before hook (which runs in the main process before individual test workers are created), those changes should ideally be persisted and sent to the individual test workers when they are created, if persist_globals setting is enabled.

More context: https://discord.com/channels/618399631038218240/1194196887650185237/1194196887650185237
Previous work and discussion on passing settings to individual workers: #3791 (comment)
(Though instead of passing settings, we only need to pass the globals this time.)

Steps to reproduce

  • Create a globals.js file and a sample test file shown below.
  • Run the test in parallel mode.

Sample test

// globals.js
let newVar = {};

module.exports = {
  newVar: newVar,
  before: () => {
    newVar['setting'] = 'something';
  },
};


// test/sampleTest.js
describe('Ecosia.org Demo', function() {
  before(browser => browser.navigateTo('https://www.ecosia.org/'));

  it('Demo test ecosia.org', async function(browser) {
    console.log(browser.globals.newVar);  // will be empty object
  });
});

Command to run

npx nightwatch ./test

Verbose Output

No response

Nightwatch Configuration

No response

Nightwatch.js Version

3.3.7

Node Version

No response

Browser

No response

Operating System

No response

Additional Information

No response

@capGoblin
Copy link

Hi @garg3133, As we already pass settings to individual workers, I wonder if we can add the globals_path for globals.js to settings inorder to pass globals, whenever the persist_globals setting is enabled ?

@capGoblin capGoblin linked a pull request Mar 25, 2024 that will close this issue
9 tasks
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

Successfully merging a pull request may close this issue.

2 participants