Read more

Cucumber step to pick a datetime in Rails' horrible datetime_select

Henning Koch
May 12, 2015Software engineer at makandra GmbH

Please don't use the horrible datetime_select Show archive.org snapshot helper. It has a terrible UI. Always prefer to use a visual time picker like Rome Show archive.org snapshot instead.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

In case everything has failed and you do need a Cucumber step to pick a datetime datetime_select, here it is:

When(/^I select the time (\d+)\-(\d+)\-(\d+) (\d+):(\d+) from "(.*?)"$/) do |year, month, day, hour, minute, label_text|
  label = page.find('label', text: label_text)
  id = label['for']
  select year,   from: "#{id}_1i"
  select month,  from: "#{id}_2i"
  select day,    from: "#{id}_3i"
  select hour,   from: "#{id}_4i"
  select minute, from: "#{id}_5i"
end
Posted by Henning Koch to makandra dev (2015-05-12 08:57)