Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
70 lines (54 sloc) 1.98 KB
module Hermes
# A few actions built on top of Capybara.
module Actions
POSTFIXES = {
:year => '1i',
:month => '2i',
:day => '3i',
:hour => '4i',
:minute => '5i'
}.freeze
def select_datetime(datetime, options={})
select_prefix = select_prefix_from_options(options)
select_time(datetime, :id_prefix => select_prefix)
select_date(datetime, :id_prefix => select_prefix)
end
def select_time(time, options={})
select_prefix = select_prefix_from_options(options)
find_and_select_option(select_prefix,
POSTFIXES[:hour],
string_with_double_digits(time.hour))
find_and_select_option(select_prefix,
POSTFIXES[:minute],
string_with_double_digits(time.min))
end
def select_date(date, options={})
select_prefix = select_prefix_from_options(options)
find_and_select_option(select_prefix, POSTFIXES[:year], date.year)
find_and_select_option(select_prefix, POSTFIXES[:month], date.month)
find_and_select_option(select_prefix, POSTFIXES[:day], date.day)
end
private
def find_and_select_option(select_prefix, postfix, value)
full = "#{select_prefix}_#{postfix}"
select = find(:css, "##{full}")
select.find(:xpath, ".//option[contains(./@value, '#{value}')]").select_option
end
def string_with_double_digits(number)
"%.2d" % number
end
def select_prefix_from_options(options)
if options.slice(:id_prefix, :from).values.blank?
raise(ArgumentError, 'You must supply either :from or :id_prefix option')
end
select_prefix = options[:id_prefix]
select_prefix ||= find_prefix_by_label(options[:from])
select_prefix
end
def find_prefix_by_label(label)
find(:xpath,
"//label[contains(normalize-space(string(.)), '#{label}')]"
)['for'].sub(/_\di$/, '')
end
end
end
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.