I've attempted to create a before hook in Cucumber.js; this is my first time trying this via Cucumber.js.
Question: I'm wondering how Cucumber knows of the hook in my step definition. And does it automatically call that code for me after requiring it in my world.js?
I mean below I added the var hooks = require('./beforeHooks.js'); in my world.js; I'm wondering if Cucumber.js looks for a certain directory called hooks or do you have to call or use code you defined in your world.js such as the hooks I brought in through my require?
Example (I do not know if this is 100% correct yet):
support/beforeHooks.js
"use strict";
var phantom = require('phantom');
var beforeHooks = function () {
this.Before(function(scenario, callback) {
console.log(scenario.getName(), "(" + scenario.getUri() + ":" + scenario.getLine() + ")");
phantom.create("--web-security=no", "--ignore-ssl-errors=yes", { port: 3000 }, function (ph) {
var phantomProcess = ph;
this.createBrowserPage = function(){
phantomProcess.createPage(function(page) {
this.headlessPage = page;
});
};
});
callback();
});
};
module.exports = beforeHooks;
support/world.js
"use strict";
var hooks = require('./beforeHooks.js');
var World = function World(callback) {
callback();
};
module.exports.World = World;
support/viewCustomerList.js - my step definitions
"use strict";
var viewCustomerList = function() {
this.World = require("../../support/world.js").World;
var page = this.headlessPage;
this.Given(/^I visit the customers display page$/, function (callback) {
page.open("/", function(status){
status.should.equal("success");
callback();
});
});
};
module.exports = viewCustomerList;
Aucun commentaire:
Enregistrer un commentaire