简体   繁体   English

如何在黄瓜上写测试?

[英]How to write a test in cucumber?

This is my first test case with cucumber and I am having tough time to figure out one thing. 这是我用黄瓜做的第一个测试用例,我很难解决一件事。 So I already have a test which check user creation. 因此,我已经有了一个检查用户创建的测试。 I want to add more steps like on user create create account and create product and set some attributes to these objects. 我想添加更多类似用户创建帐户和创建产品的步骤,并为这些对象设置一些属性。

Here is the user create feature file 这是用户创建功能文件

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

So where exactly I can add steps saying create account table and product table. 所以我可以在哪里添加创建帐户表和产品表的步骤。 Thanks 谢谢

Is your 'create user account' method something that you need for each test to run? 您的“创建用户帐户”方法是否需要运行每个测试? If so, I'd just create a helper that you can call before your scenario. 如果是这样,我只会创建一个可以在您的方案之前调用的助手。 ..something like @needs_new_account. ..类似@needs_new_account的东西。 One of the best parts about cucumber is the ability to reuse environments. 关于黄瓜最好的部分之一是重用环境的能力。 You probably shouldn't create a new account for each scenario. 您可能不应该为每种情况创建一个新帐户。 Instead, have cucumber remember that it needs to keep that new account (ie., dont delete it) and reuse for the rest of your scenarios, if possible. 相反,让Cucumber记住,它需要保留该新帐户(即,不要删除它),并在可能的情况下重复使用其余的方案。 Let me know if this helps. 让我知道是否有帮助。 ..not quite sure I'm understanding your question completely. ..不太确定我是否完全理解您的问题。

Also, you don't need your extra "and" between "and" and "when"...Gherkin syntax treats And/When/Then the same. 另外,您不需要在“和”与“何时”之间添加多余的“和” ...小黄瓜语法将“和/何时/那么”视为相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM