如何在我的功能场景Cucumber.js中使用标签

How to use the tags in my function scenario Cucumber.js?

本文关键字:js 标签 Cucumber 我的 功能      更新时间:2023-09-26

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

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

事实上,我有一个场景:

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

这是我用来获取cucumber 3.0.7 的特性或场景标签的方法

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