Skip to content

Step argument transformations

Rajesh Poola edited this page Dec 25, 2024 · 1 revision

If you want to keep it really short you can use the step transformations that comes with Reqnroll.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 Reqnroll feature that describes how Step Argument Transformation are used (https://docs.reqnroll.net/latest/automation/step-argument-conversions.html)

In Reqnroll.Assist.Dynamic three transformations comes out of the box; from Reqnroll Table to dynamic instance, from Reqnroll Table to List and transformation from Reqnroll Table to IEnumerable.

To use these add the following to your app.config-file (under the -node):

<stepAssemblies>
  <stepAssembly assembly="Reqnroll.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);
}
Clone this wiki locally