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_script(script) ⇒ Object
- #execute_script(script) ⇒ 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
- #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_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 |
# File 'lib/capybara/webkit/browser.rb', line 6 def initialize(connection) @connection = connection end |
Instance Method Details
#accept_alert(options) ⇒ Object
190 191 192 |
# File 'lib/capybara/webkit/browser.rb', line 190 def accept_alert() command("AcceptAlert", [:text]) end |
#accept_confirm(options) ⇒ Object
146 147 148 |
# File 'lib/capybara/webkit/browser.rb', line 146 def accept_confirm() command("SetConfirmAction", "Yes", [:text]) end |
#accept_js_confirms ⇒ Object
150 151 152 |
# File 'lib/capybara/webkit/browser.rb', line 150 def accept_js_confirms command("SetConfirmAction", "Yes") end |
#accept_js_prompts ⇒ Object
170 171 172 |
# File 'lib/capybara/webkit/browser.rb', line 170 def accept_js_prompts command("SetPromptAction", "Yes") end |
#accept_prompt(options) ⇒ Object
162 163 164 165 166 167 168 |
# File 'lib/capybara/webkit/browser.rb', line 162 def accept_prompt() if [:with] command("SetPromptAction", "Yes", [:text], [:with]) else command("SetPromptAction", "Yes", [:text]) end end |
#alert_messages ⇒ Object
62 63 64 |
# File 'lib/capybara/webkit/browser.rb', line 62 def JSON.parse(command("JavascriptAlertMessages")) end |
#allow_unknown_urls ⇒ Object
292 293 294 |
# File 'lib/capybara/webkit/browser.rb', line 292 def allow_unknown_urls allow_url("*") end |
#allow_url(url) ⇒ Object
280 281 282 |
# File 'lib/capybara/webkit/browser.rb', line 280 def allow_url(url) command("AllowUrl", url) end |
#authenticate(username, password) ⇒ Object
10 11 12 |
# File 'lib/capybara/webkit/browser.rb', line 10 def authenticate(username, password) command("Authenticate", username, password) end |
#block_unknown_urls ⇒ Object
288 289 290 |
# File 'lib/capybara/webkit/browser.rb', line 288 def block_unknown_urls command("SetUnknownUrlMode", "block") end |
#block_url(url) ⇒ Object
284 285 286 |
# File 'lib/capybara/webkit/browser.rb', line 284 def block_url(url) command("BlockUrl", url) end |
#body ⇒ Object
42 43 44 |
# File 'lib/capybara/webkit/browser.rb', line 42 def body command("Body") end |
#clear_cookies ⇒ Object
251 252 253 |
# File 'lib/capybara/webkit/browser.rb', line 251 def command "ClearCookies" end |
#clear_prompt_text ⇒ Object
186 187 188 |
# File 'lib/capybara/webkit/browser.rb', line 186 def clear_prompt_text command("ClearPromptText") end |
#clear_proxy ⇒ Object
264 265 266 |
# File 'lib/capybara/webkit/browser.rb', line 264 def clear_proxy command("SetProxy") end |
#command(name, *args) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/capybara/webkit/browser.rb', line 204 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 read_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
66 67 68 |
# File 'lib/capybara/webkit/browser.rb', line 66 def JSON.parse(command("JavascriptConfirmMessages")) end |
#console_messages ⇒ Object
50 51 52 53 54 |
# File 'lib/capybara/webkit/browser.rb', line 50 def JSON.parse(command("ConsoleMessages")).map do || .inject({}) { |m,(k,v)| m.merge(k.to_sym => v) } end end |
#current_url ⇒ Object
78 79 80 |
# File 'lib/capybara/webkit/browser.rb', line 78 def current_url command("CurrentUrl") end |
#enable_logging ⇒ Object
14 15 16 |
# File 'lib/capybara/webkit/browser.rb', line 14 def enable_logging command "EnableLogging" end |
#error_messages ⇒ Object
56 57 58 59 60 |
# File 'lib/capybara/webkit/browser.rb', line 56 def .select do || [:message] =~ /Error:/ end end |
#evaluate_script(script) ⇒ Object
226 227 228 229 |
# File 'lib/capybara/webkit/browser.rb', line 226 def evaluate_script(script) json = command('Evaluate', script) JSON.parse("[#{json}]").first end |
#execute_script(script) ⇒ Object
231 232 233 |
# File 'lib/capybara/webkit/browser.rb', line 231 def execute_script(script) command('Execute', script) end |
#find_css(query) ⇒ Object
34 35 36 |
# File 'lib/capybara/webkit/browser.rb', line 34 def find_css(query) command("FindCss", query).split(",") end |
#find_modal(id) ⇒ Object
194 195 196 |
# File 'lib/capybara/webkit/browser.rb', line 194 def find_modal(id) command("FindModal", id) end |
#find_xpath(query) ⇒ Object
30 31 32 |
# File 'lib/capybara/webkit/browser.rb', line 30 def find_xpath(query) command("FindXpath", query).split(",") end |
#frame_focus(selector = nil) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/capybara/webkit/browser.rb', line 82 def frame_focus(selector=nil) if selector.respond_to?(:base) selector.base.invoke('focus') elsif selector.is_a? Fixnum command("FrameFocus", "", selector.to_s) elsif selector command("FrameFocus", selector) else command("FrameFocus") end end |
#get_cookies ⇒ Object
255 256 257 |
# File 'lib/capybara/webkit/browser.rb', line 255 def command("GetCookies").lines.map{ |line| line.strip }.select{ |line| !line.empty? } end |
#get_window_handle ⇒ Object
136 137 138 |
# File 'lib/capybara/webkit/browser.rb', line 136 def get_window_handle command('GetWindowHandle') end |
#get_window_handles ⇒ Object
126 127 128 |
# File 'lib/capybara/webkit/browser.rb', line 126 def get_window_handles JSON.parse(command('GetWindowHandles')) end |
#go_back ⇒ Object
272 273 274 |
# File 'lib/capybara/webkit/browser.rb', line 272 def go_back command("GoBack") end |
#go_forward ⇒ Object
276 277 278 |
# File 'lib/capybara/webkit/browser.rb', line 276 def go_forward command("GoForward") end |
#header(key, value) ⇒ Object
22 23 24 |
# File 'lib/capybara/webkit/browser.rb', line 22 def header(key, value) command("Header", key, value) end |
#ignore_ssl_errors ⇒ Object
94 95 96 |
# File 'lib/capybara/webkit/browser.rb', line 94 def ignore_ssl_errors command("IgnoreSslErrors") end |
#prompt_messages ⇒ Object
70 71 72 |
# File 'lib/capybara/webkit/browser.rb', line 70 def JSON.parse(command("JavascriptPromptMessages")) end |
#reject_confirm(options) ⇒ Object
154 155 156 |
# File 'lib/capybara/webkit/browser.rb', line 154 def reject_confirm() command("SetConfirmAction", "No", [:text]) end |
#reject_js_confirms ⇒ Object
158 159 160 |
# File 'lib/capybara/webkit/browser.rb', line 158 def reject_js_confirms command("SetConfirmAction", "No") end |
#reject_js_prompts ⇒ Object
178 179 180 |
# File 'lib/capybara/webkit/browser.rb', line 178 def reject_js_prompts command("SetPromptAction", "No") end |
#reject_prompt(options) ⇒ Object
174 175 176 |
# File 'lib/capybara/webkit/browser.rb', line 174 def reject_prompt() command("SetPromptAction", "No", [:text]) end |
#render(path, width, height) ⇒ Object
235 236 237 |
# File 'lib/capybara/webkit/browser.rb', line 235 def render(path, width, height) command "Render", path, width, height end |
#reset! ⇒ Object
38 39 40 |
# File 'lib/capybara/webkit/browser.rb', line 38 def reset! command("Reset") end |
#response_headers ⇒ Object
74 75 76 |
# File 'lib/capybara/webkit/browser.rb', line 74 def response_headers JSON.parse(command("Headers")) end |
#set_cookie(cookie) ⇒ Object
247 248 249 |
# File 'lib/capybara/webkit/browser.rb', line 247 def () command "SetCookie", end |
#set_prompt_text_to(string) ⇒ Object
182 183 184 |
# File 'lib/capybara/webkit/browser.rb', line 182 def set_prompt_text_to(string) command("SetPromptText", string) end |
#set_proxy(options = {}) ⇒ Object
259 260 261 262 |
# File 'lib/capybara/webkit/browser.rb', line 259 def set_proxy( = {}) = .merge() command("SetProxy", [:host], [:port], [:user], [:pass]) end |
#set_skip_image_loading(skip_image_loading) ⇒ Object
98 99 100 |
# File 'lib/capybara/webkit/browser.rb', line 98 def set_skip_image_loading(skip_image_loading) command("SetSkipImageLoading", skip_image_loading) end |
#status_code ⇒ Object
46 47 48 |
# File 'lib/capybara/webkit/browser.rb', line 46 def status_code command("Status").to_i end |
#timeout ⇒ Object
243 244 245 |
# File 'lib/capybara/webkit/browser.rb', line 243 def timeout command("GetTimeout").to_i end |
#timeout=(timeout_in_seconds) ⇒ Object
239 240 241 |
# File 'lib/capybara/webkit/browser.rb', line 239 def timeout=(timeout_in_seconds) command "SetTimeout", timeout_in_seconds end |
#title ⇒ Object
26 27 28 |
# File 'lib/capybara/webkit/browser.rb', line 26 def title command("Title") end |
#url_blacklist=(black_list) ⇒ Object
198 199 200 201 202 |
# File 'lib/capybara/webkit/browser.rb', line 198 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
268 269 270 |
# File 'lib/capybara/webkit/browser.rb', line 268 def version command("Version") end |
#visit(url) ⇒ Object
18 19 20 |
# File 'lib/capybara/webkit/browser.rb', line 18 def visit(url) command "Visit", url end |
#window_close(selector) ⇒ Object
110 111 112 |
# File 'lib/capybara/webkit/browser.rb', line 110 def window_close(selector) command("WindowClose", selector) end |
#window_focus(selector) ⇒ Object
102 103 104 |
# File 'lib/capybara/webkit/browser.rb', line 102 def window_focus(selector) command("WindowFocus", selector) end |
#window_handle ⇒ Object
140 141 142 143 144 |
# File 'lib/capybara/webkit/browser.rb', line 140 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
130 131 132 133 134 |
# File 'lib/capybara/webkit/browser.rb', line 130 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
122 123 124 |
# File 'lib/capybara/webkit/browser.rb', line 122 def window_maximize(handle) command("WindowMaximize", handle) end |
#window_open ⇒ Object
106 107 108 |
# File 'lib/capybara/webkit/browser.rb', line 106 def window_open command("WindowOpen") end |
#window_resize(handle, width, height) ⇒ Object
114 115 116 |
# File 'lib/capybara/webkit/browser.rb', line 114 def window_resize(handle, width, height) command("WindowResize", handle, width.to_i, height.to_i) end |
#window_size(handle) ⇒ Object
118 119 120 |
# File 'lib/capybara/webkit/browser.rb', line 118 def window_size(handle) JSON.parse(command("WindowSize", handle)) end |