0

这是我的第一个黄瓜测试用例,我很难弄清楚一件事。所以我已经有一个检查用户创建的测试。我想添加更多步骤,例如用户创建创建帐户和创建产品并为这些对象设置一些属性。

这是用户创建功能文件

@no-database-cleaner

Feature: Creating an user account
  In order to use Recdns portal
  I need to create an user account

  Scenario:  Successful user account creation
    Given the database contains no test data
    And I am on the homepage
    When I attempt to create the following user account:
      | email address        | password | confirm password |
      | abc@company1.com  | password | password         |
  # User is automatically logged in
    Then I should see "Welcome!" message on page
    And an ar_id is set for the user
    And
    When I click "Sign Out"
    Then I should see "Signed out"
    When I attempt to sign in with following user account:
      | email address         | password |
      | abc@company1.com   | password |
    Then I should see "Welcome!" message on page

  Scenario Outline:  Verify error message when user failed to sign in
    Given there is a user
    And I am on the homepage
    And I try to login with email "<email address>", password "<password>"
    Then I should see "<error message>" message on page

  Examples:
    | email address                        | password          | error message                        |
    | testuser@company1.com                | abc1234           | Invalid email or password            |
    | testuserdoesnotexist@company1.com    | password          | Invalid email or password            |

  Scenario Outline:  Verify error message when user failed to sign up
    Given I am on the homepage
    And I click "Sign Up"
    And I try to create user with email "<email address>", password "<password>", confirm password "<confirm password>"
    Then I should see "<error message>" message on page

  Examples:
    | email address       | password          | confirm password      | error message                        |
    | abc@company1.com | abc123            | abc123                | Email has already been taken         |
    | xyz@test         | abc123            | abc123                | Email is invalid                     |
    |                     | abc123            | abc123                | Email can't be blank                 |
    | abc@company1.com |                   | abc123                | Password can't be blank              |
    | abc@company1.com | abc123            |                       | Password doesn't match confirmation  |
    | abc@company1.com | abc1              | abc1                  | Password is too short                |

所以我可以在哪里添加创建帐户表和产品表的步骤。谢谢

4

1 回答 1

0

您的“创建用户帐户”方法是否需要运行每个测试?如果是这样,我只会创建一个助手,您可以在场景之前调用它。..类似@needs_new_account 的东西。Cucumber 最好的部分之一是重用环境的能力。您可能不应该为每个场景创建一个新帐户。相反,让 cucumber 记住它需要保留该新帐户(即,不要删除它)并在可能的情况下在其余场景中重复使用。让我知道这是否有帮助。..不太确定我完全理解你的问题。

此外,您不需要在“and”和“when”之间添加额外的“and”……Gherkin 语法对 And/When/Then 的处理方式相同。

于 2013-05-24T17:12:44.740 回答