Argument conversionIn Specflow, argument transformations are done effortlessly by itself from a feature to step definition, If we create an step with integer value, then specflow will deal with it automatically Similarly specflow deals with .Net types automatically
- Booleans etc
Step Argument transformationThere comes, Step argument transformation feature of specflow, which can be used to apply a custom conversion step for the arguments of the step definitions. The step argument transformation is a method that provides a conversion from text (specified by a regular expression) or from a Table instance to an arbitrary .NET type.
To achieve step argument transformationTo achieve step argument transformation following rules needs to be followed
- the return type of the transformation is the same as the parameter type
- the regular expression (if specified) is matching to the original (string) argument
- if there are multiple matching transformation available, a warning is provided in the trace and the first transformation is used
Thanks for reading the post and watching the video!!! Please leave your comments and let me know if there is anything I should update in this post. Thanks, Karthik KK
One Reply to “Step argument transformation in Specflow”
Is it possible to do argument transformation for a field in a table using a Regular Expression?
I have a table like
| PromptDate | PromptCount | LastUpdatedTimeStamp |
| Today | 2 | 2 hours ago |
PromptDate and LastUpdatedTimeStamp are both Datetime types in my object.
I would want to convert ‘Today’ to Current Date, which is DateTime.Today and transform 2 hours ago to DateTime.Now.AddHours(-2).
How can this be done in Specflow ?