DSL.Reqnroll is Reqnroll plugin that enables use of dynamic test data in Reqnroll steps by bringing in custom and environment variables, built-in functions, regular expressions and bespoke transformations. It's re-write of [SpecFlow.DSL](https://github.com/wenyuansong/Specflow.DSL) library, written originally by [Wenyuan(Ryan)](https://github.com/wenyuansong) and [Liam Flanagan](https://github.com/JovialJerboa), to align it with Reqnroll with multiple enhancements on the top. Warning: !! IParameterTransformer interface becomes obsolete in version 1.2.0 - it will be removed in the future. Please use IUserVariableTransformer interface from DSL.ReqnrollPlugin.Transformers namespace which also has _AddBespokeTransformer_ method to add bespoke transformations. Capabilities: -> Built-in functions: TODAY, RANDOM (from v1.2.0) -> Retrieve value of environment variables (from v1.1.0) -> Create dynamic test data and refer it in another step -> Create dynamic test data using regular expression -> Simple calculations via bespoke transformations
$ dotnet add package DSL.ReqnrollDSL.Reqnroll is Reqnroll plugin that enables use of dynamic test data in Reqnroll steps by bringing in custom and environment variables, built-in functions, regular expressions and bespoke transformations.
It's re-write of SpecFlow.DSL library, written originally by Wenyuan(Ryan) and Liam Flanagan, to align it with Reqnroll with multiple enhancements on the top.
In December 2024, Tricentis announced the end-of-life of the SpecFlow open source project. According to the announcement, SpecFlow reached its end-of-life on December 31, 2024. As of 1st January 2025, the SpecFlow GitHub projects have been deleted and the support section of the specflow.org website is disabled.
(( )) //double parentheses in any text will trigger matching with environment variables of the machine executing the test
((PATH)) //will get a value of PATH environmental variable
[[ ]] //double square bracket in any text will trigger pattern matching for custom variables
[[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
{{ }} //double curly brackets in any text will trigger pattern matching for built-in function and execute it
{{TODAY}} //will execute TODAY function and return current UTC timestamp in a default formatting as dd-MM-yyyy
{{L#TODAY#dd-MM-yyyy}} //will execute TODAY function and return curretn timestamp in local time of the machine executing the test formatting the output as dd-MM-yyyy
{{U#TODAY-7d#dd-MM-yyyy HH:mm:ss}} //will execute TODAY function and return UTC timestamp from 7 days ago formatting the output as dd-MM-yyyy HH:mm:ss
{{RANDOM}} //will execute RANDOM function and return pseudo random number from a default range between 1 and Int32.MaxValue (2147483647)
{{RANODM:20:80}} //will execute RANDOM function and return pseudo random number from range between 20 and 80
Changes to interfaces and namespaces: In order to employ clean code principles and prepare the code base for further enhancements some interfaces and namespaces have changed in version 1.2.0.
Users of DSL.Reqnroll plugin are using IParameterTransformer interface and AddBespokeTransformer method to add custom transformers. IParameterTransformer interface becomes obsolete in version 1.2.0 - it may still be used but it will be removed in the future. It is adviced for users to use IUserVariableTransformer interface from DSL.ReqnrollPlugin.Transformers namespace, which also has AddBespokeTransformer method to add bespoke transformations.
How custom variables work: It actually creates key/value pairs in current ScenarioContext. So be careful not to conflict with your own context variables.
How TODAY works: You can add or subtract from current timestamp the following periods: d - day M - month y - year H - hour m - minute s - second
You cannot combine the periods.
Allowed: {{TODAY+1d}} {{TODAY-10m}} Not allowed: {{TODAY+1d-6h}}
To define output format you can use the following characters: dMyHhmsftz.-\/: and space
When executed on Windows machine
Then verify string "{ OS: '((OS))', TMP: 'C:\Users\((USERNAME))\AppData\Local\Temp' }" equals "{ OS: 'Windows_NT', TMP: '((TMP))' }"
When enter [[var=50]] //assign 50 to a variable named "var"
Then [[var]] equals 50 // now get variable "var" value
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
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 bespoke transformation
Please note that IParameterTransformer interface becomes obsolete in version 1.2.0 - it may still be used but it will be removed in the future. It is adviced for users to use IUserVariableTransformer interface from DSL.ReqnrollPlugin.Transformers namespace, which also has AddBespokeTransformer method to add bespoke transformations.
for example, you want to map Today to YYYY:MM:dd programmatically, add the following code in one of your Reqnroll steps
or put it in BeforeScenario step.
((IUserVariableTransformer)
(_scenarioContext.GetBindingInstance(typeof(IUserVariableTransformer))))
.AddBespokeTransformer(s => s.ToLower() == today ? DateTime.Now.ToString("yyyy/MM/dd", CultureInfo.InvariantCulture) : s);
Now in Reqnroll feature files, you can write:
When entered "[[timeVar=Today]]" //timeVar will be assigned to yyyy/MM/dd, e.g 2017/12/04
License: MIT (https://github.com/nowakpi/DSL.Reqnroll/blob/master/LICENSE)
NuGet: https://www.nuget.org/packages/DSL.Reqnroll
Install plugin from NuGet into your Reqnroll project.
PM> Install-Package DSL.Reqnroll
In case you use App.config file, ensure the following lines have been added to enable plugin:
<plugins>
<add name="DSL" type="Runtime"/>
</plugins>