Cucumber:场景大纲重用示例表 [英] Cucumber: Scenario Outline reusing examples table

查看:19
本文介绍了Cucumber:场景大纲重用示例表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些测试如下:

Scenario Outline: Add two numebrs
  Given two numbers <number_1> and <number_2>
  When I add them
  Then Result is <number_3>

  Examples:
    |number_1|number_2|number_3|
    |2       |3       |5       |
    |1       |2       |3       |

Scenario Outline: Update two numebrs
  Given two numbers <number_1> and <number_2>
  When I update them
  Then Result is <number_3>

  Examples:
    |number_1|number_2|number_3|
    |2       |3       |5       |
    |1       |2       |3       |

对于每个测试,我应该添加相同的表格示例.

For each test I should add the same table Examples.

有什么方法可以提取此表以对所有测试使用同一个表?

Is any way to extract this table to use the same one for all tests?

推荐答案

你可以使用 qaf-gherkin 您可以在其中移动外部文件中的示例并将其用于一个或多个场景.使用 qaf,您的功能文件可能如下所示:

You can use qaf-gherkin where you can move examples in external file and use it with one or more scenario. With qaf your feature file may look like below:

Scenario Outline: Add two numebrs
  Given two numbers <number_1> and <number_2>
  When I add them
  Then Result is <number_3>

  Examples::{'datafile':'resources/testdata.txt'}

Scenario Outline: Update two numebrs
  Given two numbers <number_1> and <number_2>
  When I update them
  Then Result is <number_3>
  Examples:{'datafile':'resources/testdata.txt'}

您的数据文件将如下所示:

And your datafile will look like:

  #col.separator=|
  number_1|number_2|number_3
  2|3|5       
  1|2|3       

以上是带有 | 的 csv(宪章分隔值)数据提供者的示例作为分隔符.您还可以使用不同的数据提供者来提供来自任何 excel/xml/json/database 的数据.

Above is example of csv (charter separated values) data provider with | as seperator. You also can use different data providers to provide data from any of excel/xml/json/database.

qaf-cucumberBDD2 支持可与 Cumber 5 一起使用的黄瓜.

qaf-cucumber has BDD2 support with cucumber that can be used with Cumber 5.

这篇关于Cucumber:场景大纲重用示例表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆