【问题标题】:How to pass values obtained from one senario to another in cucumber tests?如何在黄瓜测试中将从一种场景获得的值传递给另一种场景?
【发布时间】:2020-08-15 14:32:15
【问题描述】:

我希望能够使用cucumber来测试以下场景

Feature: test

  Scenario: Start a service 
    When I start a service
    Then I obtain a token

  Scenario: Customers join a service
    When I have a token
    Then open a url and apply the token

底层实现在 typescript 中。

在第一个场景中,我将生成一个令牌。有了令牌,我想打开一个特定的 url 并在那里使用令牌。

如何将令牌从一个场景传递到另一个场景?

【问题讨论】:

    标签: cucumber cucumberjs


    【解决方案1】:

    您不应该将价值从一种场景传递到另一种场景。每个场景都应该被视为一个独立的测试。请尝试使用背景为每个场景设置一个新令牌。

      Background: Start a service 
        When I start a service
        Then I obtain a token
    
      Scenario: Customers join a service
        When I have a token
        Then open a url and apply the token
    

    或者最好将start a serviceobtain a tokenhave a token 推入一个have obtained a token from a service

      Scenario: Customers join a service
        Given the customers have obtained a token from a service
        Then open a url and apply the token
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      • 2020-07-11
      相关资源
      最近更新 更多