首页 文章

在Cucumber的Scenario Outline结束时多次调用@After

提问于
浏览
0

我的黄瓜嫩黄瓜看起来像这样:

Feature: Story XYZ- Title of Story
  """
  Title: Story XYZ- Title of Story  
  """

  Background: 
    Given Appointments are being created using "SOAP" API

  @scenario1
  Scenario Outline: Create an appointment for a New start service order    
    Given Appointment does not exist for order id "Test_PR_Order123"
    When Request for create appointment is received for order "Test_PR_Order123" and following
      | FieldName        | FieldValue         |
      | ServiceGroupName | <ServiceGroupName> |
      | SerivceGroupID   | TestSG123          |
      | ServiceType      | <ServiceType>      |
    Then Appointment ID should be created
    And Appointment for order "Test_PR_Order123" should have following details
      | FieldName        | FieldValue         |
      | ServiceGroupName | <ServiceGroupName> |
      | SerivceGroupID   | TestSG123          |
      | ServiceType      | <ServiceType>      |
    And Appointment history should exist for "Create Appointment"

Examples: 
  | ServiceType | ServiceGroupName      |
  | Service1    | ServiceGroup1         |
  | Service2    | ServiceGroup2         |

@scenario22
  Scenario Outline: Create an appointment for a Change Service order
    Given Appointment does not exist for order id "Test_CH_Order123"
    When Request for create appointment is received for order "Test_CH_Order123" and following
      | FieldName        | FieldValue         |
      | ServiceGroupName | <ServiceGroupName> |
      | SerivceGroupID   | TestSG123          |
      | ServiceType      | <ServiceType>      |
    Then Appointment ID should be created
    And Appointment for order "Test_CH_Order123" should have following details
      | FieldName        | FieldValue         |
      | ServiceGroupName | <ServiceGroupName> |
      | SerivceGroupID   | TestSG123          |
      | ServiceType      | <ServiceType>      |
    And Appointment history should exist for "Create Appointment"

Examples: 
  | ServiceType | ServiceGroupName      |
  | Service1    | ServiceGroup1         |
  | Service2    | ServiceGroup2         |

在上面的功能中,有一个背景将在两个场景大纲中为每个示例执行 . 此外,在java实现中,我们实现了@After和@Before钩子,它们也将针对每个示例执行 .

我们使用spring-cucumber在步骤之间进行数据注入 .

当第一个场景大纲中的所有示例结束时,出现问题,@ Afterfter方法被调用2次 . 当第二次@After同时开始时,第二个场景大纲示例开始执行 . 结果,场景的顺序执行受到干扰,自动化开始失败 .

请告知这是黄瓜的错误还是我们遗漏了什么 .

1 回答

  • 0

    您缺少的许多事情之一就是保持场景简单 . 通过使用场景概述并在您的小黄瓜中嵌入如此多的技术细节,您将使自己变得更加困难 . 此外,您使用钩子之前和之后使用它 .

    另一个问题是你的场景没有意义 . 它们都是关于订单的约会,但您不会在任何时候创建订单 .

    最后,你有两个相同的场景,你说做不同的事情 . 第一个是New,第二个是Change . 必须有一些区别,否则你不需要第二种情况 .

    我要做的是尝试从这个纠结中提取一个场景,并用它来诊断任何问题 . 你应该能够得到像这样的东西

    Scenario: Create an appointment for an order
      Given there is an order
      And appointments are made using SOAP
      When a new start appointment is made for the order
      Then the appointment should be created
      And the appointment should have a history
    

    如果没有任何@before或@after,你就没有理由不能使这个场景工作 . 当你有这个工作,然后创建其他情况,无论你试图检查的其他情况 . 您应该能够在不执行以下任何操作的情况下执行此操作

    • 使用示例数据来区分方案

    • 使用轮廓

    • 使用@before和@after

    使用Cucumber时,您希望将自动化的复杂性推到Cucumber之外 . 在Cucumber启动之前将其提升到脚本,或者将其推送到在单步定义中调用的辅助方法中执行 . 如果你保持Cucumber的复杂性,特别是尝试和链接场景,并使用@before和@after来保持场景之间的状态,你就不会有愉快的时间使用(误用)Cucumber .

    你的问题很可能是由你的代码引起的,而不是由Cucumbers造成的 . 即使Cucumber确实有轮廓和钩子的问题,你也可以通过不使用它们来解决问题 . 大纲完全没必要,钩子大多被滥用 .

相关问题