在小黄瓜背景中放置每个场景需要不同数据的步骤

Put a step that requires different data per secnario in a gherkin background

我正在测试一个在机场使用的应用程序。对于我的小黄瓜功能之一,我需要几个场景,这些场景都在飞行中执行一个动作。每个场景都需要它自己的航班,数据略有不同。

理想情况下,我想将 'create flight' 放在背景中,因为每个场景都需要飞行。我的问题是这个后台步骤需要为每个场景使用不同的数据,我不确定 cucumber 是否支持。

简化,我想做这样的事情:

Feature: Arrival flights

Background:
    Given I am logged in to the application
    And a flight is created with the following data
    | Scenario  | Origin     | ETA    | Flightno | Airline
    | 1         | AMS        | 12:00  | 1111     | KM
    | 2         | LIS        | 13:00  | 2222     | TS

Scenario: User is able to open a flight
    When the user opens flight 'Flightno'
    Then flight 'Flightno' is opened

Scenario: User is able to open the open a flight
    When the user opens flight 'Flightno'
    And the user clicks the 'edit flight' button
    Then the edit flight interface is opened for flight 'Flightno'

重复使用同一个航班不是一种选择,使用场景大纲也是如此

任何人都可以建议一个好的方法,而不必在每个场景中都放置 'create flight' 步骤吗?

如果没有办法做到这一点,并且 'create flight' 必须在每个场景中,有人可以建议我应该使用什么关键字来开始这一步吗?由于创建航班实际上并不是我想要测试的,所以我会说它是 'Given'。但由于我的背景已经以 'Given' 开头,这将导致 2 'Given' 个步骤。

我可以把 'And' 放在它前面,但这会使场景本身以 'And' 开头,我认为这看起来有点奇怪。 我知道从技术上讲这没有任何区别,但我想知道可接受的做法是什么。

提前致谢!

这可能是简化问题的产物,但您示例中的细节大多是虚假的。你根本不需要提到它们,因为它们与场景无关。

在不丢失任何东西的情况下,您可以将场景编写为:

Feature: Arrival flights

  Scenario: User is able to open a flight
    Given there is flight
    When the user opens the flight
    Then flight is opened

  Scenario: User is able to open the open a flight
    Given there is flight
    When the user opens the flight
    Then user clicks the 'edit flight' button
    And the edit flight interface is opened for the flight

there is flight 步骤中,您将使用随机但唯一的数据创建航班,并在某处保留对该航班的引用。在接下来的引用“航班”的步骤中,您将使用您创建的航班。

组织此上下文数据可能需要一些工作,但查看屏幕播放模式会更容易。

https://cucumber.io/blog/bdd/understanding-screenplay-(part-1)/

另请注意,您无需每次都提及您已登录。作为 user opens the flight 步骤的一部分,这样做是完全可以的。