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
- #authenticate(username, password) ⇒ 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.
5 6 7 |
# File 'lib/capybara/webkit/browser.rb', line 5 def initialize(connection) @connection = connection end |
Instance Method Details
#accept_alert(options) ⇒ Object
189 190 191 |
# File 'lib/capybara/webkit/browser.rb', line 189 def accept_alert() command("AcceptAlert", [:text]) end |
#accept_confirm(options) ⇒ Object
145 146 147 |
# File 'lib/capybara/webkit/browser.rb', line 145 def accept_confirm() command("SetConfirmAction", "Yes", [:text]) end |
#accept_js_confirms ⇒ Object
149 150 151 |
# File 'lib/capybara/webkit/browser.rb', line 149 def accept_js_confirms command("SetConfirmAction", "Yes") end |
#accept_js_prompts ⇒ Object
169 170 171 |
# File 'lib/capybara/webkit/browser.rb', line 169 def accept_js_prompts command("SetPromptAction", "Yes") end |
#accept_prompt(options) ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/capybara/webkit/browser.rb', line 161 def accept_prompt() if [:with] command("SetPromptAction", "Yes", [:text], [:with]) else command("SetPromptAction", "Yes", [:text]) end end |
#alert_messages ⇒ Object
61 62 63 |
# File 'lib/capybara/webkit/browser.rb', line 61 def JSON.parse(command("JavascriptAlertMessages")) end |
#authenticate(username, password) ⇒ Object
9 10 11 |
# File 'lib/capybara/webkit/browser.rb', line 9 def authenticate(username, password) command("Authenticate", username, password) end |
#body ⇒ Object
41 42 43 |
# File 'lib/capybara/webkit/browser.rb', line 41 def body command("Body") end |
#clear_cookies ⇒ Object
237 238 239 |
# File 'lib/capybara/webkit/browser.rb', line 237 def command "ClearCookies" end |
#clear_prompt_text ⇒ Object
185 186 187 |
# File 'lib/capybara/webkit/browser.rb', line 185 def clear_prompt_text command("ClearPromptText") end |
#clear_proxy ⇒ Object
250 251 252 |
# File 'lib/capybara/webkit/browser.rb', line 250 def clear_proxy command("SetProxy") end |
#command(name, *args) ⇒ Object
201 202 203 204 205 206 207 208 209 210 |
# File 'lib/capybara/webkit/browser.rb', line 201 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 end |
#confirm_messages ⇒ Object
65 66 67 |
# File 'lib/capybara/webkit/browser.rb', line 65 def JSON.parse(command("JavascriptConfirmMessages")) end |
#console_messages ⇒ Object
49 50 51 52 53 |
# File 'lib/capybara/webkit/browser.rb', line 49 def JSON.parse(command("ConsoleMessages")).map do || .inject({}) { |m,(k,v)| m.merge(k.to_sym => v) } end end |
#current_url ⇒ Object
77 78 79 |
# File 'lib/capybara/webkit/browser.rb', line 77 def current_url command("CurrentUrl") end |
#enable_logging ⇒ Object
13 14 15 |
# File 'lib/capybara/webkit/browser.rb', line 13 def enable_logging command "EnableLogging" end |
#error_messages ⇒ Object
55 56 57 58 59 |
# File 'lib/capybara/webkit/browser.rb', line 55 def .select do || [:message] =~ /Error:/ end end |
#evaluate_script(script) ⇒ Object
212 213 214 215 |
# File 'lib/capybara/webkit/browser.rb', line 212 def evaluate_script(script) json = command('Evaluate', script) JSON.parse("[#{json}]").first end |
#execute_script(script) ⇒ Object
217 218 219 |
# File 'lib/capybara/webkit/browser.rb', line 217 def execute_script(script) command('Execute', script) end |
#find_css(query) ⇒ Object
33 34 35 |
# File 'lib/capybara/webkit/browser.rb', line 33 def find_css(query) command("FindCss", query).split(",") end |
#find_modal(id) ⇒ Object
193 194 195 |
# File 'lib/capybara/webkit/browser.rb', line 193 def find_modal(id) command("FindModal", id) end |
#find_xpath(query) ⇒ Object
29 30 31 |
# File 'lib/capybara/webkit/browser.rb', line 29 def find_xpath(query) command("FindXpath", query).split(",") end |
#frame_focus(selector = nil) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/capybara/webkit/browser.rb', line 81 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
241 242 243 |
# File 'lib/capybara/webkit/browser.rb', line 241 def command("GetCookies").lines.map{ |line| line.strip }.select{ |line| !line.empty? } end |
#get_window_handle ⇒ Object
135 136 137 |
# File 'lib/capybara/webkit/browser.rb', line 135 def get_window_handle command('GetWindowHandle') end |
#get_window_handles ⇒ Object
125 126 127 |
# File 'lib/capybara/webkit/browser.rb', line 125 def get_window_handles JSON.parse(command('GetWindowHandles')) end |
#go_back ⇒ Object
258 259 260 |
# File 'lib/capybara/webkit/browser.rb', line 258 def go_back command("GoBack") end |
#go_forward ⇒ Object
262 263 264 |
# File 'lib/capybara/webkit/browser.rb', line 262 def go_forward command("GoForward") end |
#header(key, value) ⇒ Object
21 22 23 |
# File 'lib/capybara/webkit/browser.rb', line 21 def header(key, value) command("Header", key, value) end |
#ignore_ssl_errors ⇒ Object
93 94 95 |
# File 'lib/capybara/webkit/browser.rb', line 93 def ignore_ssl_errors command("IgnoreSslErrors") end |
#prompt_messages ⇒ Object
69 70 71 |
# File 'lib/capybara/webkit/browser.rb', line 69 def JSON.parse(command("JavascriptPromptMessages")) end |
#reject_confirm(options) ⇒ Object
153 154 155 |
# File 'lib/capybara/webkit/browser.rb', line 153 def reject_confirm() command("SetConfirmAction", "No", [:text]) end |
#reject_js_confirms ⇒ Object
157 158 159 |
# File 'lib/capybara/webkit/browser.rb', line 157 def reject_js_confirms command("SetConfirmAction", "No") end |
#reject_js_prompts ⇒ Object
177 178 179 |
# File 'lib/capybara/webkit/browser.rb', line 177 def reject_js_prompts command("SetPromptAction", "No") end |
#reject_prompt(options) ⇒ Object
173 174 175 |
# File 'lib/capybara/webkit/browser.rb', line 173 def reject_prompt() command("SetPromptAction", "No", [:text]) end |
#render(path, width, height) ⇒ Object
221 222 223 |
# File 'lib/capybara/webkit/browser.rb', line 221 def render(path, width, height) command "Render", path, width, height end |
#reset! ⇒ Object
37 38 39 |
# File 'lib/capybara/webkit/browser.rb', line 37 def reset! command("Reset") end |
#response_headers ⇒ Object
73 74 75 |
# File 'lib/capybara/webkit/browser.rb', line 73 def response_headers Hash[command("Headers").split("\n").map { |header| header.split(": ") }] end |
#set_cookie(cookie) ⇒ Object
233 234 235 |
# File 'lib/capybara/webkit/browser.rb', line 233 def () command "SetCookie", end |
#set_prompt_text_to(string) ⇒ Object
181 182 183 |
# File 'lib/capybara/webkit/browser.rb', line 181 def set_prompt_text_to(string) command("SetPromptText", string) end |
#set_proxy(options = {}) ⇒ Object
245 246 247 248 |
# File 'lib/capybara/webkit/browser.rb', line 245 def set_proxy( = {}) = .merge() command("SetProxy", [:host], [:port], [:user], [:pass]) end |
#set_skip_image_loading(skip_image_loading) ⇒ Object
97 98 99 |
# File 'lib/capybara/webkit/browser.rb', line 97 def set_skip_image_loading(skip_image_loading) command("SetSkipImageLoading", skip_image_loading) end |
#status_code ⇒ Object
45 46 47 |
# File 'lib/capybara/webkit/browser.rb', line 45 def status_code command("Status").to_i end |
#timeout ⇒ Object
229 230 231 |
# File 'lib/capybara/webkit/browser.rb', line 229 def timeout command("GetTimeout").to_i end |
#timeout=(timeout_in_seconds) ⇒ Object
225 226 227 |
# File 'lib/capybara/webkit/browser.rb', line 225 def timeout=(timeout_in_seconds) command "SetTimeout", timeout_in_seconds end |
#title ⇒ Object
25 26 27 |
# File 'lib/capybara/webkit/browser.rb', line 25 def title command("Title") end |
#url_blacklist=(black_list) ⇒ Object
197 198 199 |
# File 'lib/capybara/webkit/browser.rb', line 197 def url_blacklist=(black_list) command("SetUrlBlacklist", *Array(black_list)) end |
#version ⇒ Object
254 255 256 |
# File 'lib/capybara/webkit/browser.rb', line 254 def version command("Version") end |
#visit(url) ⇒ Object
17 18 19 |
# File 'lib/capybara/webkit/browser.rb', line 17 def visit(url) command "Visit", url end |
#window_close(selector) ⇒ Object
109 110 111 |
# File 'lib/capybara/webkit/browser.rb', line 109 def window_close(selector) command("WindowClose", selector) end |
#window_focus(selector) ⇒ Object
101 102 103 |
# File 'lib/capybara/webkit/browser.rb', line 101 def window_focus(selector) command("WindowFocus", selector) end |
#window_handle ⇒ Object
139 140 141 142 143 |
# File 'lib/capybara/webkit/browser.rb', line 139 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
129 130 131 132 133 |
# File 'lib/capybara/webkit/browser.rb', line 129 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
121 122 123 |
# File 'lib/capybara/webkit/browser.rb', line 121 def window_maximize(handle) command("WindowMaximize", handle) end |
#window_open ⇒ Object
105 106 107 |
# File 'lib/capybara/webkit/browser.rb', line 105 def window_open command("WindowOpen") end |
#window_resize(handle, width, height) ⇒ Object
113 114 115 |
# File 'lib/capybara/webkit/browser.rb', line 113 def window_resize(handle, width, height) command("WindowResize", handle, width.to_i, height.to_i) end |
#window_size(handle) ⇒ Object
117 118 119 |
# File 'lib/capybara/webkit/browser.rb', line 117 def window_size(handle) JSON.parse(command("WindowSize", handle)) end |