gpt4 book ai didi

javascript - Cucumber JS 获取当前功能/场景/世界步骤

转载 作者:数据小太阳 更新时间:2023-10-29 04:15:51 26 4
gpt4 key购买 nike

如何获取当前的功能、场景和世界步数?

我试过这种方式,但我只有场景名称和描述:

module.exports = function () {
/**
* Before each scenario
*/
this.Before(function (scenario, callback) {
console.log(scenario);
callback();
});
};

感谢您的帮助。

最佳答案

好的,所以我终于找到了这个解决方案:创建一个在 hooks 中调用的 Context 对象。

hooks.js 文件:

var context = require(process.cwd() + '/src/e2e/support/context');

module.exports = function Hooks() {

this.BeforeFeature(function (event, callback) {
context.setCurrentFeature(event.getPayloadItem('feature'));

callback();
});

this.BeforeScenario(function (event, callback) {
context.setCurrentScenario(event.getPayloadItem('scenario'));

callback();
});

this.BeforeStep(function (event, callback) {
context.setCurrentStep(event.getPayloadItem('step'));

callback();
});
};

context 对象只有 getter/setter 方法。

您现在可以在代码中的任何位置访问当前功能/场景/步骤。

以我为例,在世界中:

var context = require(process.cwd() + '/src/e2e/support/context');

module.exports = function () {
this.World = function World(callback) {
this.handleError = function (error, callback) {
var _this = this;

browser.takeScreenshot().then(function (imageData) {
var formatFeature = helperString.slugify(context.getCurrentFeature().getName());
var formatScenario = helperString.slugify(context.getCurrentScenario().getName());

var token = formatFeature + '_' + formatScenario;
var path = process.cwd() + '/logs/test/e2e/';

var pngStream = fs.createWriteStream(path + token + '_screenshot.png') ;

pngStream.write(new Buffer(imageData, 'base64'));
pngStream.end();

_this.delayCallback(function handleErrorCallback() {
callback.fail(new Error(error));
});
});

return _this;
};
};
};

关于javascript - Cucumber JS 获取当前功能/场景/世界步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27605001/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com