Unable to access world methods in the AfterFeatures interface.

I have an AfterFeatures hook that I use to try to gracefully shut down the expressjs web server, which is used only for testing. In this case, I need to call the visit method that was added to World, but I apparently do not have access to World from this hook. What can I do to access things in the World inside this and other hooks?

// features/support/after_hooks.js
var myAfterHooks = function () {
  this.registerHandler('AfterFeatures', function (event, callback) {
    this.visit('/quit', callback);
  });
};
module.exports = myAfterHooks;
+4
source share
1 answer

I do not think you can. In AfterFeatures, the cucumber process has already been completed, so this one no longer refers to it.

, , AfterFeatures. AngularJS + Protractor, Protractor , hook AfterFeatures. . .

hooks.js

var myHooks = function () {


    this.registerHandler('AfterFeatures', function (event, callback) {
      console.log('----- AfterFeatures hook');
      // This will not work as the World is no longer valid after the features
      // outside cucumber
      //this.visit('/quit', callback);  

      // But the browser is now handled by Protractor so you can do this
      browser.get('/quit').then(callback);
    });

};

module.exports = myHooks;

world.js

module.exports = function() {

  this.World = function World(callback) {

    this.visit = function(url) {
        console.log('visit ' + url);
        return browser.get(url);
    };

    callback();
  };
}

AfterFeatures cucumber-js GitHub , , , . -js, .

, registerHandler.

this.AfterFeatures(function (event, callback) {
     browser.get('/quit').then(callback);
});

, .

+2

All Articles