SpecFlow - Can I reuse test data in a properties file?

Is there a way to reuse data in specific SpecFlow files? For instance. I have two scripts that use the same data table:

Scenario: Some scenario 1 Given I have a data table | Field Name | Value | | Name | "Tom" | | Age | 16 | When ... Scenario: Some scenario 2 Given I have a data table | Field Name | Value | | Name | "Tom" | | Age | 16 | And I have another data table | Field Name | Value | | Brand | "Volvo" | | City | "London" | When ... 

In these simple examples, the tables are small and there is no big problem, however in my case the tables have 20 + rows and at least 5 tests will be used.

I would suggest something like this:

 Having data table "Employee" | Field Name | Value | | Name | "Tom" | | Age | 16 | Scenario: Some scenario 1 Given I have a data table "Employee" When ... Scenario: Some scenario 2 Given I have a data table "Employee" And I have another data table | Field Name | Value | | Brand | "Volvo" | | City | "London" | When ... 

I could not find anything like this in the SpecFlow documentation. The only suggestion for sharing data was to put it in *.cs files. However, I cannot do this because the Feature Feature will be used by non-technical people.

+6
source share
2 answers

A background is a place for shared data like this, until the data gets too large and your background section spans several pages. It seems like this could be so.

You specify tables with 20 + rows each and having multiple data tables like this. That would be a lot to get readers to get to the Scripts. Is there any other way to describe the data? When I had data tables like this in the past, I put the parts in the instrument class in the automation code and then described only the important aspects in the Feature file.

Assuming, as an example, that β€œTom” is a potential buyer of cars, and you are managing a car dealership, then its data table may include:

 | Field | Value | | Name | Tom | | Age | 16 | | Address | .... | | Phone Number | .... | | Fav Colour | Red | | Country | UK | 

Your scenario 2 may be β€œLess than 18 years old should not be able to buy a car” (at least in the UK). Given this scenario, we do not care that Tom has a phone address, only his age. We could write this script as:

 Scenario: Under 18s shouldnt be able to buy a car Given there is a customer "Tom" who is under 16 When he tries to buy a car Then I should politely refuse 

Instead of storing this Tom parts table in the Feature file, we simply reference the relevant parts. When the Given step starts, automation can search for a β€œTom” from our fixtures. The step refers to its age, so that: a) it is understandable to the reader of the Feature file that Tom belongs to, and b) to make sure that the device data is still valid.

The reader of this script will immediately understand what is important for Tom (he is 16), and they do not need to constantly refer between the script and the background. Other scripts may also use Tom, and if they are interested in other aspects of his information (for example, Address), then they can provide relevant information Given there is a customer "Tom" who lives at 10 Downing Street .

Which approach best depends on which of the data you have. If this is a small number of fields across several tables, then we put them in the background, but as soon as it becomes 10 + fields or a large number of tables (presumably, we have many potential clients), I would suggest moving it outside the Feature file and just describe relevant information in each scenario.

+5
source

Yes, you are using background, i.e. from https://github.com/cucumber/cucumber/wiki/Background

 Background: Given I have a data table "Employee" | Field Name | Value | | Name | "Tom" | | Age | 16 | Scenario: Some scenario 1 When ... Scenario: Some scenario 2 Given I have another data table | Field Name | Value | | Brand | "Volvo" | | City | "London" | 

If you are not sure what I find http://www.specflow.org/documentation/Using-Gherkin-Language-in-SpecFlow/ a great resource

+3
source

All Articles