Skip to content

An enhancement to Specflow DSL to bring variables and simple calculations to specflow steps

License

Notifications You must be signed in to change notification settings

wenyuansong/Specflow.DSL

Repository files navigation

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:

  • Create dynamic test data and refer it in another step
	When enter [[var=50]]         //assign 50 to a variable named "var"
	Then [[var]] equals 50    // now get variable "var" value
  • Create dynamic test data using regular expression
 	When enter [[var=RegEx([0-9]{3})]]         //assign var with 3 digit random number
	Then [[var]] is a 3 digits number          // now get variable "var" value
  • Same applies to SpecFlow tables:
 	When create new user with the following details:
     |Field   | Value                                 |
     |UserName| [[name=RegEx([a-z]{5,8})]]            |	        
     |Password| [[pwd=RegEx([a-z]{3}[0-9]{3})]]       |
     Then verify can login with username="[[name]]" and password="[[pwd]]"
  • Support customerise transformation
     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
  • Calculations are currently NOT supported but it can be done by customerisation as shown in project Examples

Dependencies:

  • .NetFramework 4.6.1+ or .NetCore 2.0+
  • SpecFlow v3.0 +
  • Fare 2.1.2 +

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

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

Installation

  • Install plugin from NuGet into your SpecFlow project.

    PM> Install-Package SpecFlow.DSL

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>

About

An enhancement to Specflow DSL to bring variables and simple calculations to specflow steps

Resources

License

Stars

Watchers

Forks

Packages

No packages published