-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Global before
and after
functions need context
#264
Global before
and after
functions need context
#264
Conversation
Adding some unit tests for these changes would help keep these features in future versions. |
👍 for tests.. |
@avaly @beatfactor : I couldn't find any tests that were verifying the existing global I'll see if I can figure out how to add those tests though. In the meantime, any pointers would be appreciated! |
There are no tests for global before / after unfortunately. However I'm a bit reluctant on giving these methods the same context as the test runner. I think they should have the same context as the globals module where they are defined. You can define environment aware globals which would likely solve your problem, so something like: module.exports = {
remote : true,
'local' : {
remote: false
},
before : function() {
if (!this.remote) {
// do something local
}
}
}; or even: module.exports = {
'local' : {
before : function() {
// do something local
}
}
}; The second approach works already, the first one needs the context change. |
Thanks @beatfactor - Will try implementing as you suggested. Closing this PR. |
…dded context for global before and after hooks - based on #264
* 'master' of github.com:beatfactor/nightwatch: 0.5.26 Fixed #274 - screenshot data still displayed in logs 0.5.25 added option to automatically send the test module name to the selenium server in the desiredCapabilities - based on #254 Added option to disable screenshot data in logs - based on #262 and added context for global before and after hooks - based on #264
I needed my
before
andafter
functions to have access to the nightwatchsettings
, so that they could do proper setup/teardown depending on if tests are using a local or remote (SauceLabs) server.This PR changes the way the functions are called such that the execution context from the runner is used, giving these functions access to
this.settings
.