如何在我的函数场景中使用标签Cucumber.js?

时间:2015-12-08 11:10:16

标签: javascript protractor bdd cucumberjs

如何在我的功能场景中使用标签?

如何知道调用我的函数的场景?

其实我有一个场景:

Feature: create module feature
  As a admin
  I want to use create module

  @createModule
  Given I am logged as 'ADMIN'
    And I am on "/admin/create"
   Then The "book_id" field should be empty

我想在我的函数中使用我的标签@createModule然后:

this.Then(/^The "?([^"]*)"? field should be empty$/, function (el) {

    if (myModule === @createModule) {
        ...
    } else if {
        ...
    }

    return main_po.checkIsEmptyElement(this, el);
});

我想获取我的标签@createModule,以指定调用的方案,或者其他替代方案,我想知道调用我的函数的场景。

  

解决了:

我补充说:

this.Before(function (scenario, callback) {
    var tags = scenario.getTags();

    this.current_module = tags[0].getName();

    callback();
});

和我的职能:

this.Then(/^The "?([^"]*)"? field should be empty$/, function (el) {

    if (this.current_module === @createModule) {
        ...
    } else if {
        ...
    }

    return main_po.checkIsEmptyElement(this, el);
});

1 个答案:

答案 0 :(得分:0)

这是我用来获取黄瓜3.0.7的功能或场景标签的内容。

let myTags = feature.pickle.tags;
    myTags.forEach(element => {
    logger.info(`My Tags: ${element.name}`);

});