有没有办法在黄瓜中用不同的数据集,单独重复执行几个步骤?

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

考虑一个场景步骤1:在一个网站上有几个可用的过滤器步骤2:我们必须从每个过滤器中选择值步骤3:然后验证显示的数据是基于过滤器应用的。

预计。

  • 从过滤器中选择一个值
  • 然后验证结果中显示的过滤值。
  • 再从过滤器中选择一个不同的值
  • 然后验证结果中显示的过滤值。

我试过用数据表从过滤器中选择值,但它是一个一个地选择所有的数据,而且验证只发生在最后,而不是在选择每个值之后,所以有什么方法可以做到选择和验证,然后像这样选择和验证。

cucumber bdd cucumber-java
1个回答
1
投票

你将不得不使用场景大纲与示例表而不是数据表。如果你想用不同的值执行相同的场景,那么你需要创建一个场景大纲,在示例表中你需要传递与过滤器相关的数据。

这就是你可以实现的方法。

功能介绍:

Feature: Title of your feature
  I want to use this template for my feature file


  Scenario Outline: Title of your scenario outline
    Given I select a value from the "<filters>"
    When I check for the filter in step
    Then I verify the filter in step

    Examples: 
      | filters  |
      | Data1   |
      | Data2   |
      | Data3   |

步骤定义:

boolean result = false;
    String filter = null;
    List<String> expectedFilters = new ArrayList<>();
    {
        expectedFilters.add("Data1");
        expectedFilters.add("Data2");
        expectedFilters.add("Data3");
    }




    @Given("I select a value from the {string}")
    public void i_select_a_value_from_the_filters(String filter)
    {
        result = false;
        this.filter = filter;
    }

    @When("I check for the filter in step")
    public void i_check_for_the_filter_in_step()
    {
        if( this.expectedFilters.contains(this.filter))
        {
            result = true;
        }
    }

    @Then("I verify the filter in step")
    public void i_verify_the_filter_in_step()
    {
        if( result )
        {
            System.out.println("Validation is successful for data [ " + this.filter + " ]" );
        }
        else
        {
            System.out.println("Validation failed!");
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.