黄瓜功能:模拟表单中的多个选择字段

时间:2014-09-02 22:18:27

标签: cucumber gherkin

我已开始在旨在管理清洁业务的应用中编写以下功能:

Feature: Creating a new cleaner 
  In order to allow Franchisees to allocate cleaners to jobs they need to be uploaded to the system

  Background:
    Given I am currently logged in to my account
    And I have navigated to the "Cleaners" page
    And I want to add a new cleaner to the database

  Scenario: Add a new cleaner to the system
    Given I have brought up the "Add Cleaner" form
    Then I will need to complete the fields within the following form:

      | first_name     | 
      | last_name      |
      | email          |
      | date_of_birth  |
      | postcode       |
      | mobile         |
      | other_phone    |
      | address_1      |
      | address_2      |
      | work_radius    |
      | **days_available** |
      | notes          |

    When I have entered valid data
    Then I can save to the database
    And I will have added a new cleaner to the system

除了欢迎评论我编写场景等的方式之外,我的主要问题是我无法弄清楚如何模拟从预先填充的字段中进行选择:

填充 days_available 应该允许特许经营者选择一周中的哪几天,以及那些日子里哪些时间可以使用清洁工。这显然可以返回仅在任何给定日期/时间显示可用清洁工的查询。

真的希望有人能解释一下这是怎么做到的吗?

1 个答案:

答案 0 :(得分:0)

快速评论您的功能文件的结构......您的功能中的“然后”步骤应该声明已成功或未成功完成某些操作。

鉴于我已登录该网站
当我向网站添加新的清洁工时 然后我应该看到Cleaner已成功添加

我建议使用易于理解的语言。您的方案不需要是如何使用该站点的说明。过多的导航步骤会使您无法跟踪场景的用途。

要准确回答有关days_available的问题,需要了解网站的结构以及如何输入days_available。您是从选择列表中选择,填写表单字段等吗?此外,由于您正在测试,您可以考虑在步骤(即散列,数组)中设​​置数据,而不是通过表格传递所有信息。

只是一些值得思考的东西。欢呼声。

根据您更新的帖子,我建议如下:

步骤And I want to add a new cleaner to the database似乎不是一个可操作的步骤,可以删除。步骤When I have entered valid data也是如此。如果您在上一步中处理填写表单,则表示您已输入有效数据。

如果您需要多个可用日期,我会考虑将其作为自己的步骤

And(/^the cleaner is available from (.*?) to (.*?) on (.*?)$/) do |start_time, end_time, day|
  #fill in start time
  #fill in end time
  #select day
end

Background:
    Given I am currently logged in to my account
    And I have navigated to the "Cleaners" page

Scenario:
    And I bring up the "Add Cleaners" form
    And I complete the form with
      | first name | Bob   |
      | last name  | Smith |
      ...
    And the cleaner is available from 0600 to 1800 on W
    When I submit the Add Cleaners form
    Then I should see the new cleaner has been successfully added