Class: Capybara::Webkit::Browser
- Inherits:
-
Object
- Object
- Capybara::Webkit::Browser
- Defined in:
- lib/capybara/webkit/browser.rb
Instance Method Summary collapse
- #accept_alert(options) ⇒ Object
- #accept_confirm(options) ⇒ Object
- #accept_js_confirms ⇒ Object
- #accept_js_prompts ⇒ Object
- #accept_prompt(options) ⇒ Object
- #alert_messages ⇒ Object
- #allow_unknown_urls ⇒ Object
- #allow_url(url) ⇒ Object
- #authenticate(username, password) ⇒ Object
- #block_unknown_urls ⇒ Object
- #block_url(url) ⇒ Object
- #body ⇒ Object
- #clear_cookies ⇒ Object
- #clear_prompt_text ⇒ Object
- #clear_proxy ⇒ Object
- #command(name, *args) ⇒ Object
- #confirm_messages ⇒ Object
- #console_messages ⇒ Object
- #current_url ⇒ Object
- #enable_logging ⇒ Object
- #error_messages ⇒ Object
- #evaluate_async_script(script, *args) ⇒ Object
- #evaluate_script(script, *args) ⇒ Object
- #execute_script(script, *args) ⇒ Object
- #find_css(query) ⇒ Object
- #find_modal(id) ⇒ Object
- #find_xpath(query) ⇒ Object
- #frame_focus(selector = nil) ⇒ Object
- #get_cookies ⇒ Object
- #get_window_handle ⇒ Object
- #get_window_handles ⇒ Object
- #go_back ⇒ Object
- #go_forward ⇒ Object
- #header(key, value) ⇒ Object
- #ignore_ssl_errors ⇒ Object
-
#initialize(connection) ⇒ Browser
constructor
A new instance of Browser.
- #prompt_messages ⇒ Object
- #raise_javascript_errors? ⇒ Boolean
- #refresh ⇒ Object
- #reject_confirm(options) ⇒ Object
- #reject_js_confirms ⇒ Object
- #reject_js_prompts ⇒ Object
- #reject_prompt(options) ⇒ Object
- #render(path, width, height) ⇒ Object
- #reset! ⇒ Object
- #response_headers ⇒ Object
- #set_cookie(cookie) ⇒ Object
- #set_prompt_text_to(string) ⇒ Object
- #set_proxy(options = {}) ⇒ Object
- #set_raise_javascript_errors(is_enabled) ⇒ Object
- #set_skip_image_loading(skip_image_loading) ⇒ Object
- #status_code ⇒ Object
- #timeout ⇒ Object
- #timeout=(timeout_in_seconds) ⇒ Object
- #title ⇒ Object
- #url_blacklist=(black_list) ⇒ Object
- #version ⇒ Object
- #visit(url) ⇒ Object
- #window_close(selector) ⇒ Object
- #window_focus(selector) ⇒ Object
- #window_handle ⇒ Object
- #window_handles ⇒ Object
- #window_maximize(handle) ⇒ Object
- #window_open ⇒ Object
- #window_resize(handle, width, height) ⇒ Object
- #window_size(handle) ⇒ Object
Constructor Details
#initialize(connection) ⇒ Browser
Returns a new instance of Browser.
6 7 8 9 |
# File 'lib/capybara/webkit/browser.rb', line 6 def initialize(connection) @connection = connection apply_defaults end |
Instance Method Details
#accept_alert(options) ⇒ Object
200 201 202 |
# File 'lib/capybara/webkit/browser.rb', line 200 def accept_alert() command("AcceptAlert", [:text]) end |
#accept_confirm(options) ⇒ Object
156 157 158 |
# File 'lib/capybara/webkit/browser.rb', line 156 def accept_confirm() command("SetConfirmAction", "Yes", [:text]) end |
#accept_js_confirms ⇒ Object
160 161 162 |
# File 'lib/capybara/webkit/browser.rb', line 160 def accept_js_confirms command("SetConfirmAction", "Yes") end |
#accept_js_prompts ⇒ Object
180 181 182 |
# File 'lib/capybara/webkit/browser.rb', line 180 def accept_js_prompts command("SetPromptAction", "Yes") end |
#accept_prompt(options) ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/capybara/webkit/browser.rb', line 172 def accept_prompt() if [:with] command("SetPromptAction", "Yes", [:text], [:with]) else command("SetPromptAction", "Yes", [:text]) end end |
#alert_messages ⇒ Object
64 65 66 |
# File 'lib/capybara/webkit/browser.rb', line 64 def JSON.parse(command("JavascriptAlertMessages")) end |
#allow_unknown_urls ⇒ Object
313 314 315 |
# File 'lib/capybara/webkit/browser.rb', line 313 def allow_unknown_urls allow_url("*") end |
#allow_url(url) ⇒ Object
301 302 303 |
# File 'lib/capybara/webkit/browser.rb', line 301 def allow_url(url) command("AllowUrl", url) end |
#authenticate(username, password) ⇒ Object
11 12 13 |
# File 'lib/capybara/webkit/browser.rb', line 11 def authenticate(username, password) command("Authenticate", username, password) end |
#block_unknown_urls ⇒ Object
309 310 311 |
# File 'lib/capybara/webkit/browser.rb', line 309 def block_unknown_urls command("SetUnknownUrlMode", "block") end |
#block_url(url) ⇒ Object
305 306 307 |
# File 'lib/capybara/webkit/browser.rb', line 305 def block_url(url) command("BlockUrl", url) end |
#body ⇒ Object
44 45 46 |
# File 'lib/capybara/webkit/browser.rb', line 44 def body command("Body") end |
#clear_cookies ⇒ Object
268 269 270 |
# File 'lib/capybara/webkit/browser.rb', line 268 def command "ClearCookies" end |
#clear_prompt_text ⇒ Object
196 197 198 |
# File 'lib/capybara/webkit/browser.rb', line 196 def clear_prompt_text command("ClearPromptText") end |
#clear_proxy ⇒ Object
281 282 283 |
# File 'lib/capybara/webkit/browser.rb', line 281 def clear_proxy command("SetProxy") end |
#command(name, *args) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/capybara/webkit/browser.rb', line 214 def command(name, *args) @connection.puts name @connection.puts args.size args.each do |arg| @connection.puts arg.to_s.bytesize @connection.print arg.to_s end check response = read_response check_javascript_errors(name) response rescue SystemCallError => exception @connection.restart raise(Capybara::Webkit::CrashError, <<-MESSAGE.strip) The webkit_server process crashed! #{exception.} This is a bug in capybara-webkit. For help with this crash, please visit: https://github.com/thoughtbot/capybara-webkit/wiki/Reporting-Crashes MESSAGE end |
#confirm_messages ⇒ Object
68 69 70 |
# File 'lib/capybara/webkit/browser.rb', line 68 def JSON.parse(command("JavascriptConfirmMessages")) end |
#console_messages ⇒ Object
52 53 54 55 56 |
# File 'lib/capybara/webkit/browser.rb', line 52 def JSON.parse(command("ConsoleMessages")).map do || .inject({}) { |m,(k,v)| m.merge(k.to_sym => v) } end end |
#current_url ⇒ Object
80 81 82 |
# File 'lib/capybara/webkit/browser.rb', line 80 def current_url command("CurrentUrl") end |
#enable_logging ⇒ Object
15 16 17 |
# File 'lib/capybara/webkit/browser.rb', line 15 def enable_logging command "EnableLogging" end |
#error_messages ⇒ Object
58 59 60 61 62 |
# File 'lib/capybara/webkit/browser.rb', line 58 def .select do || [:message] =~ /Error:/ end end |
#evaluate_async_script(script, *args) ⇒ Object
243 244 245 246 |
# File 'lib/capybara/webkit/browser.rb', line 243 def evaluate_async_script(script, *args) json = command("EvaluateAsync", script, args.to_json) JSON.parse("[#{json}]").first end |
#evaluate_script(script, *args) ⇒ Object
238 239 240 241 |
# File 'lib/capybara/webkit/browser.rb', line 238 def evaluate_script(script, *args) json = command("Evaluate", script, args.to_json) JSON.parse("[#{json}]").first end |
#execute_script(script, *args) ⇒ Object
248 249 250 |
# File 'lib/capybara/webkit/browser.rb', line 248 def execute_script(script, *args) command("Execute", script, args.to_json) end |
#find_css(query) ⇒ Object
35 36 37 |
# File 'lib/capybara/webkit/browser.rb', line 35 def find_css(query) command("FindCss", query).split(",") end |
#find_modal(id) ⇒ Object
204 205 206 |
# File 'lib/capybara/webkit/browser.rb', line 204 def find_modal(id) command("FindModal", id) end |
#find_xpath(query) ⇒ Object
31 32 33 |
# File 'lib/capybara/webkit/browser.rb', line 31 def find_xpath(query) command("FindXpath", query).split(",") end |
#frame_focus(selector = nil) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/capybara/webkit/browser.rb', line 84 def frame_focus(selector=nil) if selector.respond_to?(:base) selector.base.invoke("focus_frame") elsif selector.is_a? Integer command("FrameFocus", "", selector.to_s) elsif selector command("FrameFocus", selector) else command("FrameFocus") end end |
#get_cookies ⇒ Object
272 273 274 |
# File 'lib/capybara/webkit/browser.rb', line 272 def command("GetCookies").lines.map{ |line| line.strip }.select{ |line| !line.empty? } end |
#get_window_handle ⇒ Object
146 147 148 |
# File 'lib/capybara/webkit/browser.rb', line 146 def get_window_handle command("GetWindowHandle") end |
#get_window_handles ⇒ Object
136 137 138 |
# File 'lib/capybara/webkit/browser.rb', line 136 def get_window_handles JSON.parse(command("GetWindowHandles")) end |
#go_back ⇒ Object
289 290 291 |
# File 'lib/capybara/webkit/browser.rb', line 289 def go_back command("GoBack") end |
#go_forward ⇒ Object
293 294 295 |
# File 'lib/capybara/webkit/browser.rb', line 293 def go_forward command("GoForward") end |
#header(key, value) ⇒ Object
23 24 25 |
# File 'lib/capybara/webkit/browser.rb', line 23 def header(key, value) command("Header", key, value) end |
#ignore_ssl_errors ⇒ Object
96 97 98 |
# File 'lib/capybara/webkit/browser.rb', line 96 def ignore_ssl_errors command("IgnoreSslErrors") end |
#prompt_messages ⇒ Object
72 73 74 |
# File 'lib/capybara/webkit/browser.rb', line 72 def JSON.parse(command("JavascriptPromptMessages")) end |
#raise_javascript_errors? ⇒ Boolean
108 109 110 |
# File 'lib/capybara/webkit/browser.rb', line 108 def raise_javascript_errors? @raise_javascript_errors end |
#refresh ⇒ Object
297 298 299 |
# File 'lib/capybara/webkit/browser.rb', line 297 def refresh command("Refresh") end |
#reject_confirm(options) ⇒ Object
164 165 166 |
# File 'lib/capybara/webkit/browser.rb', line 164 def reject_confirm() command("SetConfirmAction", "No", [:text]) end |
#reject_js_confirms ⇒ Object
168 169 170 |
# File 'lib/capybara/webkit/browser.rb', line 168 def reject_js_confirms command("SetConfirmAction", "No") end |
#reject_js_prompts ⇒ Object
188 189 190 |
# File 'lib/capybara/webkit/browser.rb', line 188 def reject_js_prompts command("SetPromptAction", "No") end |
#reject_prompt(options) ⇒ Object
184 185 186 |
# File 'lib/capybara/webkit/browser.rb', line 184 def reject_prompt() command("SetPromptAction", "No", [:text]) end |
#render(path, width, height) ⇒ Object
252 253 254 |
# File 'lib/capybara/webkit/browser.rb', line 252 def render(path, width, height) command "Render", path, width, height end |
#reset! ⇒ Object
39 40 41 42 |
# File 'lib/capybara/webkit/browser.rb', line 39 def reset! apply_defaults command("Reset") end |
#response_headers ⇒ Object
76 77 78 |
# File 'lib/capybara/webkit/browser.rb', line 76 def response_headers JSON.parse(command("Headers")) end |
#set_cookie(cookie) ⇒ Object
264 265 266 |
# File 'lib/capybara/webkit/browser.rb', line 264 def () command "SetCookie", end |
#set_prompt_text_to(string) ⇒ Object
192 193 194 |
# File 'lib/capybara/webkit/browser.rb', line 192 def set_prompt_text_to(string) command("SetPromptText", string) end |
#set_proxy(options = {}) ⇒ Object
276 277 278 279 |
# File 'lib/capybara/webkit/browser.rb', line 276 def set_proxy( = {}) = .merge() command("SetProxy", [:host], [:port], [:user], [:pass]) end |
#set_raise_javascript_errors(is_enabled) ⇒ Object
104 105 106 |
# File 'lib/capybara/webkit/browser.rb', line 104 def set_raise_javascript_errors(is_enabled) @raise_javascript_errors = is_enabled end |
#set_skip_image_loading(skip_image_loading) ⇒ Object
100 101 102 |
# File 'lib/capybara/webkit/browser.rb', line 100 def set_skip_image_loading(skip_image_loading) command("SetSkipImageLoading", skip_image_loading) end |
#status_code ⇒ Object
48 49 50 |
# File 'lib/capybara/webkit/browser.rb', line 48 def status_code command("Status").to_i end |
#timeout ⇒ Object
260 261 262 |
# File 'lib/capybara/webkit/browser.rb', line 260 def timeout command("GetTimeout").to_i end |
#timeout=(timeout_in_seconds) ⇒ Object
256 257 258 |
# File 'lib/capybara/webkit/browser.rb', line 256 def timeout=(timeout_in_seconds) command "SetTimeout", timeout_in_seconds end |
#title ⇒ Object
27 28 29 |
# File 'lib/capybara/webkit/browser.rb', line 27 def title command("Title") end |
#url_blacklist=(black_list) ⇒ Object
208 209 210 211 212 |
# File 'lib/capybara/webkit/browser.rb', line 208 def url_blacklist=(black_list) warn '[DEPRECATION] Capybara::Webkit::Browser#url_blacklist= ' \ 'is deprecated. Please use page.driver.block_url instead.' command("SetUrlBlacklist", *Array(black_list)) end |
#version ⇒ Object
285 286 287 |
# File 'lib/capybara/webkit/browser.rb', line 285 def version command("Version") end |
#visit(url) ⇒ Object
19 20 21 |
# File 'lib/capybara/webkit/browser.rb', line 19 def visit(url) command "Visit", url end |
#window_close(selector) ⇒ Object
120 121 122 |
# File 'lib/capybara/webkit/browser.rb', line 120 def window_close(selector) command("WindowClose", selector) end |
#window_focus(selector) ⇒ Object
112 113 114 |
# File 'lib/capybara/webkit/browser.rb', line 112 def window_focus(selector) command("WindowFocus", selector) end |
#window_handle ⇒ Object
150 151 152 153 154 |
# File 'lib/capybara/webkit/browser.rb', line 150 def window_handle warn '[DEPRECATION] Capybara::Webkit::Browser#window_handle ' \ 'is deprecated. Please use Capybara::Session#current_window instead.' get_window_handle end |
#window_handles ⇒ Object
140 141 142 143 144 |
# File 'lib/capybara/webkit/browser.rb', line 140 def window_handles warn '[DEPRECATION] Capybara::Webkit::Browser#window_handles ' \ 'is deprecated. Please use Capybara::Session#windows instead.' get_window_handles end |
#window_maximize(handle) ⇒ Object
132 133 134 |
# File 'lib/capybara/webkit/browser.rb', line 132 def window_maximize(handle) command("WindowMaximize", handle) end |
#window_open ⇒ Object
116 117 118 |
# File 'lib/capybara/webkit/browser.rb', line 116 def window_open command("WindowOpen") end |
#window_resize(handle, width, height) ⇒ Object
124 125 126 |
# File 'lib/capybara/webkit/browser.rb', line 124 def window_resize(handle, width, height) command("WindowResize", handle, width.to_i, height.to_i) end |
#window_size(handle) ⇒ Object
128 129 130 |
# File 'lib/capybara/webkit/browser.rb', line 128 def window_size(handle) JSON.parse(command("WindowSize", handle)) end |