如果黄瓜JS中包含故障,请跳过功能文件

问题描述 投票:1回答:1

因此,如果我总共有4个测试,如果第一个测试失败,那么我想对第一个测试进行快速失败,然后我想继续运行其他三个测试/功能文件。

我不喜欢它现在正在做什么,一旦一个测试失败,它将失败,并且它将不会运行任何其他功能文件。

任何想法?

我尝试过黄瓜选项:

'fail-fast': true

但如果发生故障将停止执行

javascript selenium protractor cucumber cucumberjs
1个回答
0
投票

如果测试失败,如果您想跳过功能文件中的其余测试,则需要执行以下操作:

  1. 在每个功能文件的顶部,添加诸如@feature_<something unique>之类的标签。
  2. 添加BeforeAfter挂钩以跟踪标签并确定功能是否失败:
// a place to track all of the failed scenarios.
const failedFeatures = [];

// identifies the feature tag using the pickle object.
function getFeature(pickle) {
    return pickle.tags.map(i => i.name).filter(i => i.indexOf('@feature_') === 0)[0];
}

// determines if the feature has failed, if it has then skip this test.
Before(function ({ pickle }) {
    const feature = getFeature(pickle);
    if (failedFeatures.indexOf(feature) >= 0) {
        return 'skipped';
    }
});

// if a test has failed, record that this feature has also failed.
After(function ({ pickle, result }) {
    const feature = getFeature(pickle);
    if (result.status === 'failed') {
        failedFeatures.push(feature);
    }
});

现场演示:https://testjam.io/?p=CW0qadImXwzRUTLLgvJY

© www.soinside.com 2019 - 2024. All rights reserved.