黄瓜js - 标记为BeforeFeature

时间:2017-04-13 19:16:42

标签: protractor bdd cucumberjs

我想在CucumberJS中标记我的BeforeFeature钩子 - 量角器测试

  1. 该钩子仅针对具有该标记的特征文件运行
  2. 钩子内的代码在特征文件开始之前运行一次,而不是在每个场景之前运行
  3. e.g。 - 仅作为特征文件'abc.feature'

    在BeforeFeature中以特定用户身份登录

    在cucumberjs中现有的BeforeFeature实现如下 -

    this.registerHandler('BeforeFeature', function (feature) {
            //do common action before feature file execution
        });
    

    我不确定它是否需要标记作为参数。还有其他方法可以在BeforeFeature级别指定标签吗?

1 个答案:

答案 0 :(得分:0)

this.BeforeFeature(function(feature) {
    feature.getTags().forEach(function (tag) {
        if(tag.getName() === '@myTag') {
            //do common action before feature file execution
        }
    });
});

OR

this.BeforeFeature(function(feature) {        
    if(feature.getName() === 'ABC') {//Gherkin file => Feature: ABC
        //do common action before feature file execution
    }
});