如何在黄瓜中写一个测试?

时间:2013-05-24 15:25:56

标签: ruby-on-rails cucumber

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

以下是用户创建要素文件

@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                |

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

1 个答案:

答案 0 :(得分:0)

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

另外,你不需要额外的“和”在“和”和“当”之间...... Gherkin语法对待和/当/然后相同。