Reputation: 41
I am writing a test and I want to reuse it hence I am trying to parametrize a Whole Table. The table sits in my 'Then' Statement and depending on the team is the table that needs to be validated.
At the moment my Scenario Outline looks like this:
Given <teamName> uses this end point
And the response is a Json
When I perform a query to http:...
Then I validate all the fields I need:
|DataElement|Validation |jsonPath |
|element1 |validate that it is not null |data.structure.path|
|element2 |validate a name |data.structure.name|
So I know I could validate each Row by parametrizing the data inside the table:
|DataElement|Validation |jsonPath |
|<value> |<Specific validation performed>|<Json Path to query|
and then do examples
But as depending on which team uses this same end point, the Data Elements and validations required are very different so I want to parametrize the WHOLE table object as in:
Then I validate all the fields I need:
<TeamTable>
Examples:
|Team A Table|
|DataElement|Validation |jsonPath |
|element1 |validate that it is not null |data.structure.path|
|element2 |validate a name |data.structure.name|
|element1 |validate age is valid |data.structure.age |
|Team B Table|
|DataElement|Validation |jsonPath |
|element1 |validate is a Date |data.structure.date |
|element2 |validate something more |data.structure.something|
|element1 |validate US postcode |data.structure.postcode |
Is it possible? How can I parametrize a whole table?
Upvotes: 4
Views: 4461
Reputation: 10199
Specflow does support table params, here is an example:
When following transactions are added
| TransactionDate | TransactionAmount | AccountNumber | Type | CR/DR |
| 1/20/12 | 10,000 | 102 | Cash | DR |
| 1/20/12 | 6,500 | 106 | Cash | DR |
| 1/21/12 | 10,001 | 102 | Cash | DR |
[When(@"following transactions are added")]
public void WhenFollowingTransactionsAreAdded(Table table)
{
// Now you can either do for each
foreach (var row in table.Rows)
{
// do stuf
}
// Or use an assist helpers to map table to an object
var transactions = table.CreateSet<Transaction>();
}
For more help about Assist helpers see SpecFlow docs
More basic stuff about tables here
Upvotes: 2
Reputation: 4170
I don't think it is possible with Specflow - I might be wrong.
I also think for the kind of test you want to do it is best to use a different testing framework.
Specflow brings most value when you need to share and discuss the features with a business person. In your example the business will not be interested in the jsonPath
so I would recommend going to plain NUnit
tests where you can easily create a templated test.
Upvotes: 1