As per the docs I should be able to define
module.exports = {
before : function(browser) {
console.log('Setting up...');
},
after : function(browser) {
console.log('Closing down...');
}
}
and do something with the _browser_ object. In my case I'm running Nightwatch in Jenkins CI and I'm manually trying to log the saved screenshot file name if the test failed. But everytime I try to use the "browser" object in this methods, it's actually the done() callback which is being referenced, instead of the browser instance.
Interestingly enough, the behaviour described here in "3) Start the ChromeDriver server" shows a different interface, where the done() callback is the first parameter of the after and before globals. I'm actually using the hooks this way, because I'm running chromedriver against chrome directly -without selenium-.
Which is the expected behaviour?
Thanks in advance
use beforeEach and afterEach hook instead
@sharadJay Thanks for you response. That's what I'm using now. But they're not exactly the same. afterEach runs before "after", and thus produces a different timestamp, which results in incorrect screenshot names.
El 16 jun. 2017 1:04 p. m., "sharad jain" notifications@github.com
escribió:
use beforeEach and afterEach hook instead
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/nightwatchjs/nightwatch/issues/1487#issuecomment-309065951,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALizkdnEB92Dr3J4yg8WcCEqhV-Kvr7wks5sEqdkgaJpZM4N8e1u
.
Bump. Same behavior observed in 0.9.16, Node 7.9.0. The doc is definitely wrong.
Also contrary to the doc: done(new Error("Oops")) does not abort the suite in the before hook. Fortunately it does in beforeEach (arguably it should abort the test, but then I'd have no way to stop the suite on setup error, except exiting Node.)
This issue has been automatically marked as stale because it has not had any recent activity.
If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.
Please Upvote for fixing this. It is indeed a bug. The parameter should be removed if it is not supported. There is a valid use case for needing to get the browser object and its options at the start of a test suite, not in each test like beforeEach.
test case:
add to globals.js
"before": function(browser, done) {
console.log( (browser ) ? browser.toString() : 'sorry broswer object is null');
done();
},
output:
Debugger listening on ws://127.0.0.1:15590/f4df5add-1347-4033-aed8-ea1782b56d45
For help, see: https://nodejs.org/en/docs/inspector
sorry browser object is null
[Login] Test Suite
from the debug, it looks like it is fired too soon.
I'd be happy if it was fixed - I also need before() and not working (NW 1.2.4)
I don't even check 1.3.1 as it has a bug which made me revert it to 1.2.4
@beatfactor would be great to re-open this one.
@straris can you create a new issue and describe the problem in detail? The issue reported here is very old and has been fixed. This test example uses a before hook with the browser as argument.
@Pieras2 which bug are you referring to? could you please open a new issue for it?
Ok, I will.
@beatfactor You are incorrect. This issue has not be resolved. The issue is about lack of support for browser object in before and after hooks in globals.js. The test example that you're referring to shows before and after hooks with browser object in an individual suite - here we are talking about lack of support for such feature in globals.js.
Globals.js supports browser object only in beforeEach and afterEach hooks, but in many cases it is very much needed to use browser object before all suites are being run, not before every suite. And vice versa with the after hook.
Could you please give us an update whether and when you are planning to resolve this issue?
Most helpful comment
Please Upvote for fixing this. It is indeed a bug. The parameter should be removed if it is not supported. There is a valid use case for needing to get the browser object and its options at the start of a test suite, not in each test like beforeEach.
test case:
add to globals.js
output: