Skip to content

Instantly share code, notes, and snippets.

@merbjedi
Created March 30, 2009 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merbjedi/87679 to your computer and use it in GitHub Desktop.
Save merbjedi/87679 to your computer and use it in GitHub Desktop.
class Webrat::SeleniumSession
def fill_in(field_identifier, options)
locator = "webrat=#{Regexp.escape(field_identifier)}"
selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.type(locator, "#{options[:with]}")
end
def click_button(button_text_or_regexp = nil, options = {})
if button_text_or_regexp.is_a?(Hash) && options == {}
pattern, options = nil, button_text_or_regexp
elsif button_text_or_regexp
pattern = adjust_if_regexp(button_text_or_regexp)
end
pattern ||= '*'
locator = "button=#{pattern}"
selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.click locator
end
def click_link(link_text_or_regexp, options = {})
pattern = adjust_if_regexp(link_text_or_regexp)
locator = "webratlink=#{pattern}"
selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.click locator
end
def click_link_within(selector, link_text, options = {})
locator = "webratlinkwithin=#{selector}|#{link_text}"
selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.click locator
end
def select(option_text, options = {})
id_or_name_or_label = options[:from]
if id_or_name_or_label
select_locator = "webrat=#{id_or_name_or_label}"
else
select_locator = "webratselectwithoption=#{option_text}"
end
selenium.wait_for_element select_locator, :timeout_in_seconds => 5
selenium.select(select_locator, option_text)
end
def choose(label_text)
locator = "webrat=#{label_text}"
selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.click locator
end
def check(label_text)
locator = "webrat=#{label_text}"
selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.click locator
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment