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.
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).
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);
});
@jechazelle thanks for posting your solution I need the same functionality for a different use case :)
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.
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.
Most helpful comment
Solved :
I added :
and my function :