【发布时间】:2016-09-13 04:57:17
【问题描述】:
我用 Protractor 和 Gulp 设置 CucumberJS。我遵循了此处提供的文档: https://github.com/cucumber/cucumber-js
我有我的功能文件和步骤定义文件。我还在支持文件夹中创建了 world.js 文件,并将其加载到我的步骤定义文件中:
this.World = require("../support/world.js").World;
因此与文档中介绍的方式相同。 直到现在一切正常。
我试着在我的箱子里添加一些黄瓜钩。我按照文档中的建议在支持文件夹中创建了 hooks.js 文件,所以:
// features/support/hooks.js (this path is just a suggestion)
var myHooks = function () {
this.Before(function (callback) {
// Just like inside step definitions, "this" is set to a World instance.
// It's actually the same instance the current scenario step definitions
// will receive.
// Let's say we have a bunch of "maintenance" methods available on our World
// instance, we can fire some to prepare the application for the next
// scenario:
console.log("Before hook");
// Don't forget to tell Cucumber when you're done:
callback();
});
};
module.exports = myHooks;
文档没有说明应该如何在我的步骤定义中加载这个 hook.js 文件,所以我假设它以某种方式加载了“约定优于配置”的方法。不幸的是,文件没有加载,也没有执行 Before 方法。
有什么想法吗?
【问题讨论】:
标签: javascript cucumber bdd cucumberjs