Class: Capybara::Webkit::Browser
- Inherits:
-
Object
- Object
- Capybara::Webkit::Browser
- Defined in:
- lib/capybara/webkit/browser.rb
Instance Method Summary collapse
- #accept_js_confirms ⇒ Object
- #accept_js_prompts ⇒ 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(query) ⇒ Object
- #frame_focus(frame_id_or_index = nil) ⇒ Object
- #get_cookies ⇒ Object
- #get_window_handle ⇒ Object (also: #window_handle)
- #get_window_handles ⇒ Object (also: #window_handles)
- #header(key, value) ⇒ Object
- #ignore_ssl_errors ⇒ Object
-
#initialize(connection) ⇒ Browser
constructor
A new instance of Browser.
- #prompt_messages ⇒ Object
- #reject_js_confirms ⇒ Object
- #reject_js_prompts ⇒ Object
- #render(path, width, height) ⇒ Object
- #reset! ⇒ Object
- #resize_window(width, height) ⇒ 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
- #url_blacklist=(black_list) ⇒ Object
- #visit(url) ⇒ Object
- #window_focus(selector) ⇒ 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_js_confirms ⇒ Object
107 108 109 |
# File 'lib/capybara/webkit/browser.rb', line 107 def accept_js_confirms command("SetConfirmAction", "Yes") end |
#accept_js_prompts ⇒ Object
115 116 117 |
# File 'lib/capybara/webkit/browser.rb', line 115 def accept_js_prompts command("SetPromptAction", "Yes") end |
#alert_messages ⇒ Object
53 54 55 |
# File 'lib/capybara/webkit/browser.rb', line 53 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
33 34 35 |
# File 'lib/capybara/webkit/browser.rb', line 33 def body command("Body") end |
#clear_cookies ⇒ Object
171 172 173 |
# File 'lib/capybara/webkit/browser.rb', line 171 def command "ClearCookies" end |
#clear_prompt_text ⇒ Object
127 128 129 |
# File 'lib/capybara/webkit/browser.rb', line 127 def clear_prompt_text command("ClearPromptText") end |
#clear_proxy ⇒ Object
184 185 186 |
# File 'lib/capybara/webkit/browser.rb', line 184 def clear_proxy command("SetProxy") end |
#command(name, *args) ⇒ Object
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/capybara/webkit/browser.rb', line 135 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
57 58 59 |
# File 'lib/capybara/webkit/browser.rb', line 57 def JSON.parse(command("JavascriptConfirmMessages")) end |
#console_messages ⇒ Object
41 42 43 44 45 |
# File 'lib/capybara/webkit/browser.rb', line 41 def JSON.parse(command("ConsoleMessages")).map do || .inject({}) { |m,(k,v)| m.merge(k.to_sym => v) } end end |
#current_url ⇒ Object
69 70 71 |
# File 'lib/capybara/webkit/browser.rb', line 69 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
47 48 49 50 51 |
# File 'lib/capybara/webkit/browser.rb', line 47 def .select do || [:message] =~ /Error:/ end end |
#evaluate_script(script) ⇒ Object
146 147 148 149 |
# File 'lib/capybara/webkit/browser.rb', line 146 def evaluate_script(script) json = command('Evaluate', script) JSON.parse("[#{json}]").first end |
#execute_script(script) ⇒ Object
151 152 153 |
# File 'lib/capybara/webkit/browser.rb', line 151 def execute_script(script) command('Execute', script) end |
#find(query) ⇒ Object
25 26 27 |
# File 'lib/capybara/webkit/browser.rb', line 25 def find(query) command("Find", query).split(",") end |
#frame_focus(frame_id_or_index = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/capybara/webkit/browser.rb', line 73 def frame_focus(frame_id_or_index=nil) if frame_id_or_index.is_a? Fixnum command("FrameFocus", "", frame_id_or_index.to_s) elsif frame_id_or_index command("FrameFocus", frame_id_or_index) else command("FrameFocus") end end |
#get_cookies ⇒ Object
175 176 177 |
# File 'lib/capybara/webkit/browser.rb', line 175 def command("GetCookies").lines.map{ |line| line.strip }.select{ |line| !line.empty? } end |
#get_window_handle ⇒ Object Also known as: window_handle
101 102 103 |
# File 'lib/capybara/webkit/browser.rb', line 101 def get_window_handle command('GetWindowHandle') end |
#get_window_handles ⇒ Object Also known as: window_handles
95 96 97 |
# File 'lib/capybara/webkit/browser.rb', line 95 def get_window_handles JSON.parse(command('GetWindowHandles')) 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
83 84 85 |
# File 'lib/capybara/webkit/browser.rb', line 83 def ignore_ssl_errors command("IgnoreSslErrors") end |
#prompt_messages ⇒ Object
61 62 63 |
# File 'lib/capybara/webkit/browser.rb', line 61 def JSON.parse(command("JavascriptPromptMessages")) end |
#reject_js_confirms ⇒ Object
111 112 113 |
# File 'lib/capybara/webkit/browser.rb', line 111 def reject_js_confirms command("SetConfirmAction", "No") end |
#reject_js_prompts ⇒ Object
119 120 121 |
# File 'lib/capybara/webkit/browser.rb', line 119 def reject_js_prompts command("SetPromptAction", "No") end |
#render(path, width, height) ⇒ Object
155 156 157 |
# File 'lib/capybara/webkit/browser.rb', line 155 def render(path, width, height) command "Render", path, width, height end |
#reset! ⇒ Object
29 30 31 |
# File 'lib/capybara/webkit/browser.rb', line 29 def reset! command("Reset") end |
#resize_window(width, height) ⇒ Object
188 189 190 |
# File 'lib/capybara/webkit/browser.rb', line 188 def resize_window(width, height) command("ResizeWindow", width.to_i, height.to_i) end |
#response_headers ⇒ Object
65 66 67 |
# File 'lib/capybara/webkit/browser.rb', line 65 def response_headers Hash[command("Headers").split("\n").map { |header| header.split(": ") }] end |
#set_cookie(cookie) ⇒ Object
167 168 169 |
# File 'lib/capybara/webkit/browser.rb', line 167 def () command "SetCookie", end |
#set_prompt_text_to(string) ⇒ Object
123 124 125 |
# File 'lib/capybara/webkit/browser.rb', line 123 def set_prompt_text_to(string) command("SetPromptText", string) end |
#set_proxy(options = {}) ⇒ Object
179 180 181 182 |
# File 'lib/capybara/webkit/browser.rb', line 179 def set_proxy( = {}) = .merge() command("SetProxy", [:host], [:port], [:user], [:pass]) end |
#set_skip_image_loading(skip_image_loading) ⇒ Object
87 88 89 |
# File 'lib/capybara/webkit/browser.rb', line 87 def set_skip_image_loading(skip_image_loading) command("SetSkipImageLoading", skip_image_loading) end |
#status_code ⇒ Object
37 38 39 |
# File 'lib/capybara/webkit/browser.rb', line 37 def status_code command("Status").to_i end |
#timeout ⇒ Object
163 164 165 |
# File 'lib/capybara/webkit/browser.rb', line 163 def timeout command("GetTimeout").to_i end |
#timeout=(timeout_in_seconds) ⇒ Object
159 160 161 |
# File 'lib/capybara/webkit/browser.rb', line 159 def timeout=(timeout_in_seconds) command "SetTimeout", timeout_in_seconds end |
#url_blacklist=(black_list) ⇒ Object
131 132 133 |
# File 'lib/capybara/webkit/browser.rb', line 131 def url_blacklist=(black_list) command("SetUrlBlacklist", *Array(black_list)) end |
#visit(url) ⇒ Object
17 18 19 |
# File 'lib/capybara/webkit/browser.rb', line 17 def visit(url) command "Visit", url end |
#window_focus(selector) ⇒ Object
91 92 93 |
# File 'lib/capybara/webkit/browser.rb', line 91 def window_focus(selector) command("WindowFocus", selector) end |