Reputation: 23
I need to write a cucumber test to test datetime select behavior.
here is my sentence: When I select "2012-4-30 15:00" as the "start_time"
here is my html view:
= 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'
I tried something like When /^I select "([^"])" as the "([^"])"$/ do |date_time, label| select(date_time, from => label) end but it doesn't work. get can not find id, name for "select box" really need help!
Upvotes: 2
Views: 1509
Reputation: 146
You could use select_date cucumber helper
select_date '2014-01-01', from: 'Start Time'
example step:
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
Upvotes: 0
Reputation: 2135
This is the custom step for cucumber tests I have created for inputing to fields generated from a 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
In your test, you call it like:
When I select datetime "2014 March 2 - 19:00" as the "start_time"
Upvotes: 0
Reputation: 5474
The datetime_select
helper generates a set of select, not a single form field. You should write a custom step to assign each part of your datetime (day, month, year, hour...) to the corresponding field.
Upvotes: 1