これは、プラグインなしで実現するのは非常に簡単です。
フィーチャー名をキーに、シナリオ数を値として使用してオブジェクトを作成し、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-大規模なキューブ – Grasshopper