More Webrat implicit waiting. Only load Webrat selectors once per run, not per test

This commit is contained in:
Bryan Helmkamp 2008-12-01 22:04:24 -05:00
parent d8e205cad0
commit e88772021b
2 changed files with 21 additions and 13 deletions

View File

@ -45,7 +45,6 @@ module Webrat
:request_page, :current_dom, :request_page, :current_dom,
:selects_date, :selects_time, :selects_datetime, :selects_date, :selects_time, :selects_datetime,
:select_date, :select_time, :select_datetime, :select_date, :select_time, :select_datetime,
:wait_for_page_to_load,
:field_by_xpath, :field_by_xpath,
:field_with_id, :field_with_id,
:selenium :selenium

View File

@ -2,8 +2,6 @@ module Webrat
class SeleniumSession class SeleniumSession
def initialize(*args) # :nodoc: def initialize(*args) # :nodoc:
extend_selenium
define_location_strategies
end end
def visit(url) def visit(url)
@ -31,29 +29,31 @@ module Webrat
pattern = adjust_if_regexp(button_text_or_regexp) pattern = adjust_if_regexp(button_text_or_regexp)
end end
pattern ||= '*' pattern ||= '*'
selenium.click("button=#{pattern}") locator = "button=#{pattern}"
selenium.wait_for_element locator, 5
selenium.click locator
end end
webrat_deprecate :clicks_button, :click_button webrat_deprecate :clicks_button, :click_button
def click_link(link_text_or_regexp, options = {}) def click_link(link_text_or_regexp, options = {})
pattern = adjust_if_regexp(link_text_or_regexp) pattern = adjust_if_regexp(link_text_or_regexp)
selenium.wait_for_element "webratlink=#{pattern}", 5 locator = "webratlink=#{pattern}"
selenium.click("webratlink=#{pattern}") selenium.wait_for_element locator, 5
selenium.click locator
end end
webrat_deprecate :clicks_link, :click_link webrat_deprecate :clicks_link, :click_link
def click_link_within(selector, link_text, options = {}) def click_link_within(selector, link_text, options = {})
selenium.click("webratlinkwithin=#{selector}|#{link_text}") locator = "webratlinkwithin=#{selector}|#{link_text}"
selenium.wait_for_element locator, 5
selenium.click locator
end end
webrat_deprecate :clicks_link_within, :click_link_within webrat_deprecate :clicks_link_within, :click_link_within
def wait_for_page_to_load(timeout = 15000)
selenium.wait_for_page_to_load(timeout)
end
def select(option_text, options = {}) def select(option_text, options = {})
id_or_name_or_label = options[:from] id_or_name_or_label = options[:from]
@ -62,19 +62,25 @@ module Webrat
else else
select_locator = "webratselectwithoption=#{option_text}" select_locator = "webratselectwithoption=#{option_text}"
end end
selenium.wait_for_element select_locator, 5
selenium.select(select_locator, option_text) selenium.select(select_locator, option_text)
end end
webrat_deprecate :selects, :select webrat_deprecate :selects, :select
def choose(label_text) def choose(label_text)
selenium.click("webrat=#{label_text}") locator = "webrat=#{label_text}"
selenium.wait_for_element locator, 5
selenium.click locator
end end
webrat_deprecate :chooses, :choose webrat_deprecate :chooses, :choose
def check(label_text) def check(label_text)
selenium.check("webrat=#{label_text}") locator = "webrat=#{label_text}"
selenium.wait_for_element locator, 5
selenium.check locator
end end
webrat_deprecate :checks, :check webrat_deprecate :checks, :check
@ -114,6 +120,9 @@ module Webrat
$browser.set_speed(0) $browser.set_speed(0)
$browser.start $browser.start
teardown_at_exit teardown_at_exit
extend_selenium
define_location_strategies
end end
def teardown_at_exit #:nodoc: def teardown_at_exit #:nodoc: