2

我需要编写一个黄瓜测试来测试日期时间选择行为。

这是我的句子:当我选择“2012-4-30 15:00”作为“start_time”时

这是我的html视图:

      = form_tag time_off_requests_path do
      = label :time_off_request, :start_time, 'Start Time'
      = datetime_select :time_off_request, :start_time , :start_year => Time.current.year, :use_short_month => true

      = submit_tag 'Save Changes'

我尝试了类似 When /^I select "([^"] )" as the "([^"] )"$/ do |date_time, label| select(date_time, from => label) end 但它不起作用。get 找不到 id,name for "select box" 真的需要帮助!

4

3 回答 3

1

datetime_select助手生成一选择,而不是单个表单字段。您应该编写一个自定义步骤来将日期时间(日、月、年、小时...)的每个部分分配给相应的字段。

于 2012-04-22T12:09:25.590 回答
0

这是我为输入从 datetime_select 生成的字段而创建的黄瓜测试的自定义步骤:

When /^(?:|I )select datetime "([^ ]*) ([^ ]*) ([^ ]*) - ([^:]*):([^"]*)" as the "([^"]*)"$/ do |year, month, day, hour, minute, field|
  select(year,   :from => "#{field}_1i")
  select(month,  :from => "#{field}_2i")
  select(day,    :from => "#{field}_3i")
  select(hour,   :from => "#{field}_4i")
  select(minute, :from => "#{field}_5i")
end

在您的测试中,您将其称为:

When I select datetime "2014 March 2 - 19:00" as the "start_time"
于 2014-03-02T22:22:49.357 回答
0

你可以使用 select_date 黄瓜助手

select_date '2014-01-01', from: 'Start Time'

示例步骤:

When(/^I choose "([^"]*)" in "([^"]*)" date select$/) do |value, select_label|
  select_date value, from: select_label
end

http://www.rubydoc.info/github/cucumber/cucumber-rails/Cucumber/Rails/Capybara/SelectDatesAndTimes

于 2016-04-27T06:53:18.040 回答