问题
My requirement is to read examples from external excel file rather than hard code it into feature file. I have more than 100 examples which is difficult to maintain in feature file. Can you please help me on this.
Here is my scenario -
Scenario Outline: Browser Test
When I visit the URL <base>/<page>/<ordNumber>/<custName>
Then the browser contains test <custNumber>
Examples:
| base | page | ordNumber | custName |
| http://www.stackoverflow.com | orders | 123 | John |
| http://www.stackoverflow.com | orders | 456 | Mike |
| http://www.stackoverflow.com | orders | 789 | Tom |
I want to create an excel file with examples data and load it during runtime
examples.xls
| base | page | ordNumber | custName |
| http://www.stackoverflow.com | orders | 123 | John |
| http://www.stackoverflow.com | orders | 456 | Mike |
| http://www.stackoverflow.com | orders | 789 | Tom |
Thanks.
回答1:
What you are looking for is supported using gherkin with QAF. QAF support different external data providers including json, xml, csv, excel and DB. It also supports multiple bdd syntax.
Using Gherkin or BDD2 with QAF below is the example:
Scenario Outline: Browser Test
When I visit the URL <base>/<page>/<ordNumber>/<custName>
Then the browser contains test <custNumber>
Examples: {'datafile': 'resources/testdata/examples.xls'}
There are lots of other features as well for resource management, execution configuration, driver management and parallel execution.
回答2:
In this case, I would opt for generating the feature files based on a template and the use of a template engine (like Velocity).
For integration with Excel, you can use the POI library the read properly your *.xls file(s).
Then run the generated feature file(s) like you would with "hard-coded" ones.
Hope this helps !
来源:https://stackoverflow.com/questions/53193890/cucumber-how-to-read-examples-from-external-excel-file-for-scenarios-outline