如何让黄瓜为每个功能而不是每个场景实例化自定义世界?

问题描述 投票:0回答:1

我有一个功能,其中功能文件中的方案在逻辑上互连 - 因此我的方案无法独立运行。

Nice:我创建了一个CustomWorld,让Cucumber自己创建和销毁我的框架实例。

错误:Cucumber为每个场景创建并销毁实例。但是我想要为每个功能而不是场景创建和销毁它。

这是我的功能文件

Feature: Table Headers

  Scenario: Check the default headers ### My framework instance created here
    Given I log in to the application ### A setup
    When I navigate to the list page
    Then the table should have the below headers
      | Default Headers |
      | First Name |
      | Last Name  |
      | Age        |

  Scenario: Add columns ### want to reuse the instance created above and destroy automatically after this scenario
    When I add the below columns to display
      | Headers |
      | City    |
      | Country |
    Then the table should have the below headers
      | Default Headers |
      | First Name |
      | Last Name  |
      | Age        |
      | City    |
      | Country |
    And I log out from the application ### A teardown

我的框架:当我创建一个类的实例时,将创建一个selenium webdriver实例,打开一个浏览器并启动URL。

真正的问题:我想打开浏览器并且每个功能只启动一次URL而不是每个场景。

bdd cucumberjs
1个回答
1
投票

这打破了BDD和黄瓜的规则。您不应该在场景中具有依赖关系。我建议你的GivenBackground进行设置并且步骤不明确。

Given I am on the list page
  |Application|
  |###|
Then the table should have the below headers
  | Default Headers |
  | First Name |
  | Last Name  |
  | Age        |

Given I am on the list page
  |Application|
  |###|
When I add the below columns to display
  | Headers |
  | City    |
  | Country |
Then the table should have the below headers
  | Default Headers |
  | First Name |
  | Last Name  |
  | Age        |
  | City    |
  | Country |

也是你的最后一步并不是一个步骤,不应该包含在你的场景中它应该是AfterHook的一部分

© www.soinside.com 2019 - 2024. All rights reserved.