이것은 플러그인 없이는 매우 간단합니다.
기능 이름을 키로 사용하고 시나리오 수를 값으로 사용하여 console.log()
키로 개체를 생성하거나 나중에 볼 수 있도록 파일에 저장하는 것이 좋습니다.
나는 두 가지 방법 (2.x 구문과 1.x 구문을 보여줄 것입니다.
CucumberJS 2.x를 구문
let {defineSupportCode} = require('cucumber'),
counter = {};
defineSupportCode(({registerHandler, Before}) => {
registerHandler('BeforeFeature', function (feature, callback) {
global.featureName = function() {
return feature.name;
};
callback();
});
Before(function (scenario, callback){
counter[featureName()] !== undefined ? counter[featureName()] += 1 : counter[featureName()] = 1;
callback();
});
registerHandler('AfterFeatures', function (feature, callback) {
console.log(JSON.stringify(counter));
callback();
});
});
CucumberJS 1.x의 구문
var counter = {};
module.exports = function() {
this.BeforeFeature(function (feature, callback) {
global.featureName = function() {
return feature.name;
};
callback();
});
this.Before(function (scenario, callback){
counter[featureName()] !== undefined ? counter[featureName()] += 1 : counter[featureName()] = 1;
callback();
});
this.AfterFeatures(function (feature, callback) {
console.log(JSON.stringify(counter));
callback();
});
};
추가
파일로이 작업을 저장하려면, 그래서 나중에 그것을 볼 수 있기를 바랍니다. fs-e를 사용하는 것이 좋습니다. xtra 라이브러리. console.log()
대신에, 이것을 사용 :
fs = require('fs-extra');
fs.writeFileSync("path/to/file.js","let suite = " + JSON.stringify(counter));
유의하시기 바랍니다, 파일은 당신이 테스트를 실행 한 곳에서 생성됩니다.
Given I am running from "frameworks/cucumberjs"
When I generate a file from "frameworks/cucumberjs/hooks/counter.js" with the fs library at "./file.js"
Then the file "frameworks/cucumberjs/file.js" should exist
Given I am running from "frameworks/cucumberjs"
When I generate a file from "frameworks/cucumberjs/features/support/hooks/counter.js" with the fs library at "./hello/file.js"
Then the file "frameworks/cucumberjs/hello/file.js" should exist
올바른 디렉토리에서 실행 중인지 확인하십시오. 특징
총 수
당신은뿐만 아니라 기능의 총 수를 원하는 경우 :
console.log()
대신에
:
console.log(JSON.stringify(counter) + "\nFeature Count: " + Object.keys(counter).length)
그리고의 WriteFile의 장소 :
fs.writeFileSync("path/to/file.js","let suite = " + JSON.stringify(counter) + ", featureCount = " + Object.keys(counter).length);
시나리오 이름을 각 피쳐 이름별로 정렬 했으므로 작성한 객체 내의 키의 양을 알려 주면 피쳐 수를 계산할 수 있습니다.그 구조에서
이것 좀보세요 - http://stackoverflow.com/questions/18004326/how-can-i-get-a-quick-count-of-the-number-of-scenarios-and-steps- in-a-large-cucu – Grasshopper