Cucumber : How to read examples from external excel file for Scenarios Outline

戏子无情 提交于 2021-01-02 11:51:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!