Class: Webrat::SeleniumSession
Instance Method Summary
collapse
#silence_stream
#doc_root, #open_in_browser, #rewrite_css_and_image_references, #save_and_open_page, #saved_page_dir
Constructor Details
27
28
|
# File 'lib/webrat/selenium/selenium_session.rb', line 27
def initialize(*args)
end
|
Instance Method Details
33
34
35
|
# File 'lib/webrat/selenium/selenium_session.rb', line 33
def automate
yield
end
|
#check(label_text) ⇒ Object
Also known as:
uncheck
118
119
120
121
122
|
# File 'lib/webrat/selenium/selenium_session.rb', line 118
def check(label_text)
locator = "webrat=#{label_text}"
selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.click locator
end
|
#choose(label_text) ⇒ Object
110
111
112
113
114
|
# File 'lib/webrat/selenium/selenium_session.rb', line 110
def choose(label_text)
locator = "webrat=#{label_text}"
selenium.wait_for_element locator, :timeout_in_seconds => 5
selenium.click locator
end
|
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/webrat/selenium/selenium_session.rb', line 63
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
|
#click_link(link_text_or_regexp, options = {}) ⇒ Object
78
79
80
81
82
83
|
# File 'lib/webrat/selenium/selenium_session.rb', line 78
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
|
#click_link_within(selector, link_text, options = {}) ⇒ Object
87
88
89
90
91
|
# File 'lib/webrat/selenium/selenium_session.rb', line 87
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
|
#current_url ⇒ Object
59
60
61
|
# File 'lib/webrat/selenium/selenium_session.rb', line 59
def current_url
selenium.location
end
|
#fill_in(field_identifier, options) ⇒ Object
43
44
45
46
47
|
# File 'lib/webrat/selenium/selenium_session.rb', line 43
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
|
#fire_event(field_identifier, event) ⇒ Object
127
128
129
130
|
# File 'lib/webrat/selenium/selenium_session.rb', line 127
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
132
133
134
135
|
# File 'lib/webrat/selenium/selenium_session.rb', line 132
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
137
138
139
140
|
# File 'lib/webrat/selenium/selenium_session.rb', line 137
def key_up(field_identifier, key_code)
locator = "webrat=#{Regexp.escape(field_identifier)}"
selenium.key_up(locator, key_code)
end
|
51
52
53
|
# File 'lib/webrat/selenium/selenium_session.rb', line 51
def response
SeleniumResponse.new(self, response_body)
end
|
#response_body ⇒ Object
55
56
57
|
# File 'lib/webrat/selenium/selenium_session.rb', line 55
def response_body
selenium.get_html_source
end
|
#save_and_open_screengrab ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/webrat/selenium/selenium_session.rb', line 175
def save_and_open_screengrab
return unless File.exist?(saved_page_dir)
filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.png"
if $browser.chrome_backend?
$browser.capture_entire_page_screenshot(filename, '')
else
$browser.capture_screenshot(filename)
end
open_in_browser(filename)
end
|
#select(option_text, options = {}) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/webrat/selenium/selenium_session.rb', line 95
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
|
166
167
168
169
170
|
# File 'lib/webrat/selenium/selenium_session.rb', line 166
def selenium
return $browser if $browser
setup
$browser
end
|
30
31
|
# File 'lib/webrat/selenium/selenium_session.rb', line 30
def simulate
end
|
#visit(url) ⇒ Object
37
38
39
|
# File 'lib/webrat/selenium/selenium_session.rb', line 37
def visit(url)
selenium.open(url)
end
|
#wait_for(params = {}) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/webrat/selenium/selenium_session.rb', line 142
def wait_for(params={})
timeout = params[:timeout] || 5
message = 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(message + " (after #{timeout} sec)")
true
end
|