【问题标题】:How to use the tags in my function scenario Cucumber.js?如何在我的功能场景 Cucumber.js 中使用标签?
【发布时间】:2015-12-08 11:10:15
【问题描述】:

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

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

其实我有一种情况:

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);
});

【问题讨论】:

  • 这是一个有趣的标签用法,但很危险:更改标签不应该对测试产生影响,它们可以自动生成,适应不同的团队等。相反,您应该添加“Given我的任务是 createModule',在这一步中,您将“createModule”存储在您的世界中:this.current_module = module
  • 我正在尝试实现这样的东西。我可以知道您的示例中的“current_module”是什么吗?

标签: javascript protractor bdd cucumberjs


【解决方案1】:

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

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

});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-03
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 2022-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多