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

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

问题描述

多个场景可以使用同一个示例表吗?

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

这里是参考.

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

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