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

Global before and after functions need context #264

Closed

Conversation

geekdave
Copy link

I needed my before and after functions to have access to the nightwatch settings, 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.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling f0c0199 on geekdave:feature-before-after-context into c754381 on beatfactor:master.

@avaly
Copy link
Contributor

avaly commented Sep 15, 2014

Adding some unit tests for these changes would help keep these features in future versions.

@davidlinse
Copy link
Contributor

👍 for tests..

@geekdave
Copy link
Author

@avaly @beatfactor : I couldn't find any tests that were verifying the existing global before / after functions (there is a sampleWithBeforeAndAfter.js test, but it uses the local versions of these functions, not the global ones), so it was not immediately obvious how to demonstrate this bug with a test.

I'll see if I can figure out how to add those tests though. In the meantime, any pointers would be appreciated!

@beatfactor
Copy link
Member

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.

@geekdave
Copy link
Author

Thanks @beatfactor - Will try implementing as you suggested. Closing this PR.

@geekdave geekdave closed this Sep 16, 2014
@geekdave geekdave deleted the feature-before-after-context branch September 16, 2014 15:08
@geekdave geekdave restored the feature-before-after-context branch September 16, 2014 15:08
beatfactor added a commit that referenced this pull request Sep 16, 2014
…dded context for global before and after hooks - based on #264
beatfactor added a commit that referenced this pull request Sep 21, 2014
* '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
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 this pull request may close these issues.

5 participants