Obtain scenario name and tags in Specflow test

Posted by on May 4, 2016 in Asp.net, WebDev

I was recently tasked with obtaining the tag name(s) and title of a Specflow feature within its step definition file (C# code).
It turns out this is quite simple to do and exposed naturally within the step definitions through the TechTalk.SpecFlow.ScenaroContext class.

exposes the current scenario context, from which a ScenarioInfo property is declared. Quite conveniently, this class definition contains a string array of tags and the title, all neatly wrapped up in a single, consice class:

Therefore, anywhere in your current stepdefinition you should be able to get the title and the tags using:

Easy as that.