I am using SpecFlow with VisualStudio 2013 to test a particular web form which has the following layout
******************** Start: Form ******************
Name:________________
Age:_________________
Experience:
Work place | Number of years |
___________ | _________________ |
___________ | _________________ |
___________ | _________________ |
___________ | _________________ |
******************** End: Form ******************
How do I write it so that I can feed from Example?
Given ...
When user fills 'Name-Box' with '<name>'
And user fills 'Age-Box' with '<age>'
And user fills experience with
| Workplace | NumberOfYears |
| <workplace> | <years> |
And user clicks the 'Save' button
Then ...
Examples:
name|age
Sam|40
#note that there will be always 1 here.
Examples:
workplace|years
abc|2
xyz|3
pqr|4
The reason why I want to do it this way, is so that I can generate the example table from an external spreadsheet programmatically and change it dynamically. Is it possible to do this? or is there anything wrong?
You can, but you'll have to restucture your example table:
Each row in the form needs a "workspace X" and "years X" column in your examples table.
STR said:
That is true. If you need an unlimited number of rows, you can still restructure your test, but I don't think you can use a Scenario Outline.
You could use:
The step definition would be two parts:
Using the SpecFlow
TableExtensions
in the TechTalk.SpecFlow.Assist namespace, the class above can be used to represent each row in the SpecFlow table.If you want to define your SpecFlow example sets in a spreadsheet, you can do this using SpecFlow+ Excel. In fact you can define your entire feature files in Excel if you want to, or just extend your features with examples defined in Excel. You can make changes in Excel directly and those changes will be reflected in your test cases.
If you're interested in finding out more, there's a brief introduction at www.specflow.org/plus/excel/getting-started/ and Gaspar Nagy gave a presentation at CukeUp! 2014 that includes some examples as well as a general overview.
I should however point out that unlike SpecFlow, the SpecFlow+ components (SpecFlow+ Excel and SpecFlow+ Runner) require a license to be purchased and are not open source. You can evaluate SpecFlow+ Excel for free, but an extra scenario is generated with title “SpecFlow+ Excel Evaluation Mode” if you have not registered a license.
Note: sorry for the unclickable link, but I can't add more than 2 links :(