javacumber:结合大纲场景和数据表

vqlkdk9b  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(387)

我在问是否有任何方法可以将大纲场景和数据表结合起来,如下面的示例:

Feature: User Sign UP

  Scenario Outline: User <User> tries to signup with improper combination of password
    Given the user <User> has browsed to the signup page
    When the user <User> tries to signup entering the following details
      | email           | <Email>            |
      | password        | <Password>         |
      | confirmPassword | <ConfirmPassword>  |
    Then an error message <validation> should be shown above the password field
    Examples:
      | User    | Email                   |Password          | ConfirmPassword  | validation                         |
      | user1   | email1@gmail.com        | 234567569        | 234567569        | This password is entirely numeric. |
      | user2   | email2@gmail.com        | 123456789        | 123456789        | This password is too common.       |

java步骤类:

@When("the user (.+) tries to signup entering the following details")
    public void testAdd2(String user,DataTable dataTable) throws Throwable {
    //Asserts
    }

谢谢你的时间。

ecbunoof

ecbunoof1#

这是可能的,但不使用数据表可能更容易:

Scenario Outline: User <User> tries to signup with improper combination of password
    Given the user <User> has browsed to the signup page
    When the user <User> tries to signup entering <Email> <Password> and <Confirm Password>
    Then an error message <validation> should be shown above the password field
    Examples:
      | User    | Email                   |Password          | ConfirmPassword  | validation                         |
      | user1   | email1@gmail.com        | 234567569        | 234567569        | This password is entirely numeric. |
      | user2   | email2@gmail.com        | 123456789        | 123456789        | This password is too common.       |

和java步骤

@When("the user (.+) tries to signup entering the following (.+) (.+) and (.+)")
    public void testAdd2(String user,String email,String password,String confirmPassword,) throws Throwable {
    //Asserts
    }

但如果要使用数据表,则需要将其转换为列表,如下面的示例代码所示:

public void readDataTableElements(DataTable dt) {
    List<String> list = dt.asList(String.class);
    System.out.println("First element - " + list.get(0));
    System.out.println("Next element - " + list.get(1));

相关问题