黄瓜中的可重用/通用示例表 [英] Reusable/Generic Examples table in Cucumber

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

问题描述

是否可以在多个方案中使用相同的示例"表?

Is it possible for multiple scenarios to use the same Examples table?

所以不要像下面这样:

Scenario Outline: First Scenario
    Given I am viewing "<url>"
    Then I assert that the current URL "<url>"
    Examples:
      | url                |
      | https://google.com |
      | https://twitter.com|

  Scenario Outline: Second Scenario
    Given I am viewing "<url>" with route "</contactus>"
    Then I assert that "<url>" contains "contactus"
    Examples:
      | url                |
      | https://google.com |
      | https://twitter.com|

我可以做类似

Scenario Outline: Reusable Example
    Examples:
      | url                |
      | https://google.com |
      | https://twitter.com|

  Scenario: First Scenario
    Given I am viewing "<url>"
    Then I assert that the current URL "<url>"

  Scenario: Second Scenario
    Given I am viewing "<url>" with route "</contactus>"
    Then I assert that "<url>" contains "contactus"

我在StackOverflow上发现了一个类似的问题,但是合并了我所有的场景在一种情况下对我来说不是一个选择.自从2014年发布此问题以来,也许框架中有了一些我不知道的进步:D

I found a similar question on StackOverflow, but merging all my scenarios in just one scenario is not an option for me. Since this question was posted in 2014, maybe there have been some advancements in the framework which I am not aware of :D

先谢谢您.

推荐答案

您可以使用 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: First Scenario
   Given I am viewing "<url>"
   Then I assert that the current URL "<url>"
   Examples:{'datafile':'resources/testdata.txt'}

Scenario Outline: Second Scenario
Given I am viewing "<url>" with route "</contactus>"
Then I assert that "<url>" contains "contactus"
Examples:{'datafile':'resources/testdata.txt'}

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

And your datafile will look like:

url
https://google.com
https://twitter.com

这是参考.

这篇关于黄瓜中的可重用/通用示例表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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