Class: Webrat::SeleniumSession
- Defined in:
- lib/webrat/selenium/selenium_session.rb
Instance Method Summary collapse
- #automate ⇒ Object
- #check(label_text) ⇒ Object
- #choose(label_text) ⇒ Object
- #click_button(button_text_or_regexp = nil, options = {}) ⇒ Object
- #click_link(link_text_or_regexp, options = {}) ⇒ Object
- #click_link_within(selector, link_text, options = {}) ⇒ Object
- #fill_in(field_identifier, options) ⇒ Object
- #fire_event(field_identifier, event) ⇒ Object
-
#initialize(*args) ⇒ SeleniumSession
constructor
:nodoc:.
- #key_down(field_identifier, key_code) ⇒ Object
- #key_up(field_identifier, key_code) ⇒ Object
- #response ⇒ Object
-
#response_body ⇒ Object
:nodoc:.
- #select(option_text, options = {}) ⇒ Object
- #selenium ⇒ Object
- #simulate ⇒ Object
- #visit(url) ⇒ Object
- #wait_for(params = {}) ⇒ Object
Constructor Details
#initialize(*args) ⇒ SeleniumSession
:nodoc:
21 22 |
# File 'lib/webrat/selenium/selenium_session.rb', line 21 def initialize(*args) # :nodoc: end |
Instance Method Details
#automate ⇒ Object
27 28 29 |
# File 'lib/webrat/selenium/selenium_session.rb', line 27 def automate yield end |
#check(label_text) ⇒ Object
108 109 110 111 112 |
# File 'lib/webrat/selenium/selenium_session.rb', line 108 def check(label_text) locator = "webrat=#{label_text}" selenium.wait_for_element locator, 5 selenium.check locator end |
#choose(label_text) ⇒ Object
100 101 102 103 104 |
# File 'lib/webrat/selenium/selenium_session.rb', line 100 def choose(label_text) locator = "webrat=#{label_text}" selenium.wait_for_element locator, 5 selenium.click locator end |
#click_button(button_text_or_regexp = nil, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/webrat/selenium/selenium_session.rb', line 53 def ( = nil, = {}) if .is_a?(Hash) && == {} pattern, = nil, else pattern = adjust_if_regexp() end pattern ||= '*' locator = "button=#{pattern}" selenium.wait_for_element locator, 5 selenium.click locator end |
#click_link(link_text_or_regexp, options = {}) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/webrat/selenium/selenium_session.rb', line 68 def click_link(link_text_or_regexp, = {}) pattern = adjust_if_regexp(link_text_or_regexp) locator = "webratlink=#{pattern}" selenium.wait_for_element locator, 5 selenium.click locator end |
#click_link_within(selector, link_text, options = {}) ⇒ Object
77 78 79 80 81 |
# File 'lib/webrat/selenium/selenium_session.rb', line 77 def click_link_within(selector, link_text, = {}) locator = "webratlinkwithin=#{selector}|#{link_text}" selenium.wait_for_element locator, 5 selenium.click locator end |
#fill_in(field_identifier, options) ⇒ Object
37 38 39 40 41 |
# File 'lib/webrat/selenium/selenium_session.rb', line 37 def fill_in(field_identifier, ) locator = "webrat=#{Regexp.escape(field_identifier)}" selenium.wait_for_element locator, 5 selenium.type(locator, "#{[:with]}") end |
#fire_event(field_identifier, event) ⇒ Object
116 117 118 119 |
# File 'lib/webrat/selenium/selenium_session.rb', line 116 def fire_event(field_identifier, event) locator = "webrat=#{Regexp.escape(field_identifier)}" selenium.fire_event(locator, "#{event}") end |
#key_down(field_identifier, key_code) ⇒ Object
121 122 123 124 |
# File 'lib/webrat/selenium/selenium_session.rb', line 121 def key_down(field_identifier, key_code) locator = "webrat=#{Regexp.escape(field_identifier)}" selenium.key_down(locator, key_code) end |
#key_up(field_identifier, key_code) ⇒ Object
126 127 128 129 |
# File 'lib/webrat/selenium/selenium_session.rb', line 126 def key_up(field_identifier, key_code) locator = "webrat=#{Regexp.escape(field_identifier)}" selenium.key_up(locator, key_code) end |
#response ⇒ Object
45 46 47 |
# File 'lib/webrat/selenium/selenium_session.rb', line 45 def response SeleniumResponse.new(self, response_body) end |
#response_body ⇒ Object
:nodoc:
49 50 51 |
# File 'lib/webrat/selenium/selenium_session.rb', line 49 def response_body #:nodoc: selenium.get_html_source end |
#select(option_text, options = {}) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/webrat/selenium/selenium_session.rb', line 85 def select(option_text, = {}) id_or_name_or_label = [: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, 5 selenium.select(select_locator, option_text) end |
#selenium ⇒ Object
155 156 157 158 159 |
# File 'lib/webrat/selenium/selenium_session.rb', line 155 def selenium return $browser if $browser setup $browser end |
#simulate ⇒ Object
24 25 |
# File 'lib/webrat/selenium/selenium_session.rb', line 24 def simulate end |
#visit(url) ⇒ Object
31 32 33 |
# File 'lib/webrat/selenium/selenium_session.rb', line 31 def visit(url) selenium.open(url) end |
#wait_for(params = {}) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/webrat/selenium/selenium_session.rb', line 131 def wait_for(params={}) timeout = params[:timeout] || 5 = params[:message] || "Timeout exceeded" begin_time = Time.now while (Time.now - begin_time) < timeout value = nil begin value = yield rescue ::Spec::Expectations::ExpectationNotMetError, ::Selenium::CommandError, Webrat::WebratError value = nil end return value if value sleep 0.25 end raise Webrat::TimeoutError.new( + " (after #{timeout} sec)") true end |