-
Notifications
You must be signed in to change notification settings - Fork 27
Step argument transformations
If you want to keep it really short you can use the step transformations that comes with SpecFlow.Assist.Dynamic. A step argument transformation can simplest be described as a way to get typed object for a certain pattern in a Given/When/Then-attribute - see the SpecFlow feature that describes how Step Argument Transformation are used (https://github.com/techtalk/SpecFlow/wiki/Step-Argument-Conversions)
In SpecFlow.Assist.Dynamic three transformations comes out of the box; from SpecFlow Table to dynamic instance, from SpecFlow Table to List and transformation from SpecFlow Table to IEnumerable.
To use these add the following to your app.config-file (under the -node):
<stepAssemblies>
<stepAssembly assembly="SpecFlow.Assist.Dynamic" />
</stepAssemblies>
That configuration is added by default with the NuGet installation script.
Using this step arguments transformation is then as easy as:
Scenario:
Scenario: Test property with step argrument transformation
Given I create a dynamic instance from this table using step argument transformation
| Name | Age | Birth date | Length in meters |
| Marcus | 39 | 1972-10-09 | 1.96 |
Then the Name property should equal 'Marcus'
Step definitions:
private dynamic _instance;
[Given(@"I create a dynamic instance from this table using step argument transformation")]
public void c(dynamic instance)
{
_instance = instance;
}
[Then(@"the Name property should equal '(.*)'")]
public void NameShouldBe(string expectedValue)
{
((string)_instance.Name).Should().Equal(expectedValue);
}