Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use tag in my function scenario Cucumber.js? #469

Closed
jechazelle opened this issue Dec 8, 2015 · 5 comments
Closed

How to use tag in my function scenario Cucumber.js? #469

jechazelle opened this issue Dec 8, 2015 · 5 comments

Comments

@jechazelle
Copy link

Hi,

How to know the scenario that calls my function ? How to use the tags in my function scenario ?

Actually I have one scenario :

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

I would like to use my tag @CreateModule in my function Then :

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

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

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

I would like to get my tag @CreateModule, to specify the scenario called, or other alternative, I would like to know what scenarios call my function.

@charlierudolph
Copy link
Member

Tags are used for choosing what scenarios to run when executing cucumber-js (see the README). Currently steps don't have any way of telling what scenario they are currently being run for. All steps under a scenario will share a world instance (accessed through this in the step definition).

@jechazelle
Copy link
Author

Solved :

I added :

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

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

    callback();
});

and my function :

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

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

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

@kylezeeuwen
Copy link

@jechazelle thanks for posting your solution I need the same functionality for a different use case :)

@tompahoward
Copy link

In cucumber-js 3.2.1 I to use

Before({timeout: 20000}, async function(testCase) {
  this.tags = testCase.pickle.tags.map((tag) => tag.name);`
  ...
}

The reason I'm using it is because a particular step implementation is failing for a known subset of scenarios, so I've created a non-critical defect ticket in our tracking system, tagged the failing scenarios with the ticket# and then added logic in the step implementation to return 'pending' if this.tags contains the ticket number.

This allows out build to go back to green, while the powers that be decide if they want to fix the defect or not.

@lock
Copy link

lock bot commented May 15, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants