在方案和功能内重用dataTable

时间:2019-03-15 11:53:21

标签: cucumber bdd

这是我的功能文件(例如)

Feature: The flower story
  I bought some flowers to make a bouquet to gift it to my friend

  Scenario: Make a bouquet
    Given I have the following flowers
      | Lotus   |
      | Jasmine |
      | Rose    |
    When I make a bouquet with the flowers
    Then the bouquet should have the below flowers
      | Lotus   |
      | Jasmine |
      | Rose    |

  Scenario: Gift bouquet to my friend
    Given I have a bouquet with the following flowers
      | Lotus   |
      | Jasmine |
      | Rose    |
    When I gift it to my friend
    And he unwraps the flowers from the bouquet
    Then My friend should have the below flowers
      | Lotus   |
      | Jasmine |
      | Rose    |

问题:花(数据表)正在重复

问题:如何在需要的地方重复使用数据表(可能带有占位符)来表示花朵? (假设我不需要方案大纲)

2 个答案:

答案 0 :(得分:1)

首先,请重点关注以下语句:“ 黄瓜不是工具,这是一个思考过程”。现在,让我们首先了解什么是方案大纲。

场景概述: 简而言之,需要执行多个场景,这些场景具有相同的步骤模式和不同的输入值。

希望,这很清楚。现在转到数据表

数据表: 通过场景定义/场景大纲的特定步骤/单个步骤中的步骤定义方法,可以使用DT概念访问测试数据。数据表是在一个步骤下定义的,该步骤不能访问几个/所有步骤都可以访问数据表的地方。

将为您提供建议,对于您的方案,方案大纲应是正确的概念,而不是数据表。根据我的理解和知识,不可能在占位符下定义数据表,并不能将其用于您提到的多个步骤。

有关数据表的更多信息: 有时方案中的步骤需要描述不容易在给定,时间或然后。黄瓜数据表是用于以表格格式传递来自功能文件的测试数据的最常用方法之一。然后,您可以以列表和地图的形式在步骤定义方法中使用此数据。

答案 1 :(得分:1)

您可以使用背景:

Feature: The flower story
  I bought some flowers to make a bouquet to gift it to my friend

Background:
 Given I have the following flowers
      | Lotus   |
      | Jasmine |
      | Rose    |

  Scenario: Make a bouquet
    When I make a bouquet with the flowers
    Then the bouquet should have the below flowers
      | Lotus   |
      | Jasmine |
      | Rose    |

  Scenario: Gift bouquet to my friend
     When I gift it to my friend
    And he unwraps the flowers from the bouquet
    Then My friend should have the below flowers
      | Lotus   |
      | Jasmine |
      | Rose    |