Open kumarchandresh opened 1 year ago
+1
A workaround for this is to define beforeEach
function in globals.js
to be async.
The following would work fine even without a before
hook in the actual test:
// globals.js
module.exports = {
async beforeEach(browser, done) {
browser.window.maximize();
done();
}
}
// nightwatch.conf.js
module.exports = {
// ...
globals_path: 'globals.js',
// ...
}
So, the actual issue here is that the beforeEach
global hook doesn't function when not defined as a async
function, unless the test suite itself contains a before
hook.
This is not an issue when using mocha
as the test runner.
Description of the bug/issue
When I write a command in
beforeEach
hook inglobals.js
and don't write anybefore
orafter
hooks in the test suite, I expected that command to be executed but nightwatch skips it instead.Steps to reproduce
npm nightwatch init
command.Create and configure globals.js file.
}
// nightwatch.conf.js module.exports = {
}
Run the
ecosia.js
test from examples usingnpx nightwatch nightwatch/examples/basic/ecosia.js
.it('Demo test ecosia.org', function(browser) { browser .waitForElementVisible('body') .assert.titleContains('Ecosia') .assert.visible('input[type=search]') .setValue('input[type=search]', 'nightwatch') .assert.visible('button[type=submit]') .click('button[type=submit]') .assert.textContains('.layout__content', 'Nightwatch.js'); });
after(browser => browser.end()); });
Sample test
No response
Command to run
No response
Verbose Output
No response
Nightwatch Configuration
No response
Nightwatch.js Version
3.1.1
Node Version
18.17.0
Browser
Chrome 115.0.0
Operating System
Windows 11 Pro version 10.0.22621
Additional Information
No response