Open reallymello opened 1 year ago
In your sample test you don't have an await. Could you retry the following snippet. Your async
doesn't have an await
.
import { NightwatchBrowser } from 'nightwatch';
module.exports = {
'should take a screenshot': async (browser: NightwatchBrowser) => {
await browser.assert.fail('oops');
},
afterEach: (browser: NightwatchBrowser) => {
browser.navigateTo('https://www.ecosia.org/');
},
};
So, maybe a silly question, but if the test is marked async does it require an await? browser.assert doesn't typically need to be awaited so now I'm confused.
Preferably, yes. We can't detect if you're using await
so the test will continue without any warning and in most cases I think it will be fine, but in some situations, like yours the next testcase or the afterEach hook will start sooner than expected, so the queue might get confused.
Even though in theory the internal queue should be able to handle these situations, it's best to try and avoid them.
So in async test cases is the recommendation to await every line or ensure at least one await is used?
Yes, await every line, but you can still use chaining, you don't have to await every single command, you can await a chain as well.
I'm running into a similar issue on nightwatch 3.5.0
where screenshots aren't being taken on failure.
Sample test:
import { NightwatchAPI } from 'nightwatch'
import { Google } from '../../page-objects'
describe('Google', function () {
this.tags = ['google', 'ui']
let google: Google
before(function (browser: NightwatchAPI) {
google = browser.page.google()
})
beforeEach(function() {
google.navigate()
})
afterEach(function (browser: NightwatchAPI) {
browser.end()
})
it('image should be visible', async function () {
await browser.assert.fail('oops')
})
})
I tried making the afterEach
async and await browser.end()
and that didn't work. Tried using the done
callback and that didn't work either. Tried using arrow functions but that didn't work.
The only thing that did work was removing async from the test (it
) but I would expect it to work with a async
test function as well. It seems the like the issue is around having the test be marked as async.
Any ideas what could be happening or any recommendations? I can open a new issue if needed. I would prefer using async/await
so I don't do too many nested call backs.
Description of the bug/issue
When I run my test with screenshots enabled on failure and my test fails I expect a screenshot to be saved under the screenshots directory of the current browser screen, but this is not happening when the test is async and I am using a non-async afterEach hook.
Steps to reproduce
Sample test
Command to run
Verbose Output
Nightwatch Configuration
Nightwatch.js Version
2.6.21
Node Version
18.16.0
Browser
Chrome 113
Operating System
Windows 10
Additional Information
If the afterEach test hook is marked async the screenshot is saved, but it seems like it should work in either case
❌ afterEach: (browser: NightwatchBrowser) => {
✅ afterEach: async (browser: NightwatchBrowser) => {