How can we retrieve/get feature, scenario title and tag name in step definitions?
For example I have a feature file booksearch with a feature:
Feature: Book Search
Scenario: Title should be matched
I perform a simple search on 'abc'
------------------------
------------------------
[When(@"I perform a simple search on '(.*)'")]
public void WhenIPerformASimpleSearchOn(string searchTerm)
{
--------
----------
//custom log
WriteLogs(int stepNum,string scenarioName,string tagname,string stepDescription,string stepResult)
}
How can we retrieve/get Feature and scenario title and tag name in step definitions for given scenario?
We are using MSTest as unit test provider.
You can retrieve the feature and scenario title by querying the FeatureInfo and ScenarioInfo classes.
For example, placing the following code in you step definition (i.e. WhenIPerformASimpleSearchOn() ):
var featureTitle = FeatureContext.Current.FeatureInfo.Title;
var featureTags = FeatureContext.Current.FeatureInfo.Tags;
var featureDescription = FeatureContext.Current.FeatureInfo.Description;
var scenarioTitle = ScenarioContext.Current.ScenarioInfo.Title;
var scenarioTags = ScenarioContext.Current.ScenarioInfo.Tags;
Will retrieve the feature title, tags and description as well as the scenario title and tags.
They are part of the context, you'll probably need to look at both the ScenarioContext and the FeatureContext to get the details you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With