wenyuansong / Specflow.DSL

An enhancement to Specflow DSL to bring variables and simple calculations to specflow steps
MIT License
5 stars 2 forks source link

Specflow.DSL

An enhancement to Specflow DSL to be able to use dynamic test data in specflow steps by bringing in variables, regular expressions and simple calculations.

Syntax:

  [[ ]]                //double bracket in any text will trigger pattern matching 
  [[varName=value]]    //will create a variable named "varName" with value "value" 
  [[varName]]         //will get value of "varName", throw an error if "varName" is not defined
  [[varName=RegEx(patternText)]]  //RegEx() is a keyword that value is generated from patternText

How it works:
It actually creates key/value pairs in current ScenarioContext. So be careful not to conflict with your own context variables.

Examples:

     for example, you want to map Today to YYYY:MM:dd, add the following code in one of your Specflow steps 
     or put it in BeforeScenario step.
      ((IParameterTransform)
                (_scenarioContext.GetBindingInstance(typeof(IParameterTransform))))
            .addTransformer(s => s.ToLower() == today ? DateTime.Now.ToString("yyyy/MM/dd") : s); 

     Now in Specflow feature files, you can write:  
     When entered "[[timeVar=Today]]"         //timeVar will be assigned to yyyy/MM/dd, e.g 2017/12/04

Dependencies:

License: MIT (https://github.com/wenyuansong/Specflow.DSL/blob/master/LICENSE)

NuGet: https://www.nuget.org/packages/SpecFlow.DSL

Installation

That's it!!!

Your project's App.config file will be automatically added the following lines to enable plugin:

   <plugins>
      <add name="SpecFlow.DSL" type="Runtime"/>
    </plugins>