좋아, 결국이 해결책을 찾았습니다 : 후크라고하는 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
목적은 단지/setter 메소드를 터링하고있다.
이제 코드에서 현재 기능/시나리오/단계에 액세스 할 수 있습니다. 세계에서 내 exemple 들어
: 당신이 함수를 볼 수있는이 코드에서
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;
};
};
};
getLastStep https://github.com/cucumber/cucumber-js/blob/master/lib/cucumber /ast/scenario.js 아마도 이것이 도움이 될 수 있습니다. –