Permalink
Browse files

Added select datetime helper.

  • Loading branch information...
1 parent 1862639 commit 843f425407f24602df4b058d259caec08a615cb0 @fabioyamate fabioyamate committed Oct 31, 2010
Showing with 21 additions and 0 deletions.
  1. +21 −0 lib/hermes/actions.rb
View
@@ -9,5 +9,26 @@ def #{method}(scope, prefix=nil)
end
RUBY
end
+
+ def select_datetime(datetime, options={})
+ no_select_msg = "cannot select option, no select box with id, name, or label '#{options[:from]}' found"
+ input = find(:xpath, XPath::HTML.select(options[:from]), :message => no_select_msg)
+ select_id = input[:id].sub(/_\di$/, '')
+
+ find_and_select_option(select_id, 1, datetime.year)
+ find_and_select_option(select_id, 2, datetime.month)
+ find_and_select_option(select_id, 3, datetime.day)
+ find_and_select_option(select_id, 4, datetime.hour)
+ find_and_select_option(select_id, 5, datetime.min)
+ end
+
+ private
+ def find_and_select_option(select_id, order, value)
+ no_select_msg = "cannot select option, no select box with id, name, or label '#{select_id}' found"
+ no_option_msg = "cannot select option, no option with text '#{value}' in select box '#{select_id}'"
+ select = find(:css, "##{select_id}_#{order}i", :message => no_select_msg)
+ select.find(:xpath, ".//option[contains(./@value, '#{value}')]", :message => no_option_msg).select_option
+ end
+ end
end
end

0 comments on commit 843f425

Please sign in to comment.