Cucumber : 如何从外部 excel 文件中读取场景大纲的示例示例、大纲、场景、文件

2023-09-07 23:58:40 作者:浅听★低吟

我的要求是从外部 excel 文件中读取示例,而不是将其硬编码到功能文件中.我有 100 多个在功能文件中难以维护的示例.你能帮我解决这个问题吗?

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.

这是我的场景 -

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      |

我想创建一个包含示例数据的 excel 文件并在运行时加载它

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      |

谢谢.

推荐答案

使用 带有 QAF 的小黄瓜.QAF支持不同的外部数据提供者,包括json、xml、csv、excel和DB.它还支持多种bdd语法.

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.

下面是使用带有 QAF 的 Gherkin 或 BDD2 的示例:

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.