Class: Capybara::Webkit::Browser

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/webkit/browser.rb

Instance Method Summary collapse

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(options)
  command("AcceptAlert", options[:text])
end

#accept_confirm(options) ⇒ Object



146
147
148
# File 'lib/capybara/webkit/browser.rb', line 146

def accept_confirm(options)
  command("SetConfirmAction", "Yes", options[:text])
end

#accept_js_confirmsObject



150
151
152
# File 'lib/capybara/webkit/browser.rb', line 150

def accept_js_confirms
  command("SetConfirmAction", "Yes")
end

#accept_js_promptsObject



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(options)
  if options[:with]
    command("SetPromptAction", "Yes", options[:text], options[:with])
  else
    command("SetPromptAction", "Yes", options[:text])
  end
end

#alert_messagesObject



62
63
64
# File 'lib/capybara/webkit/browser.rb', line 62

def alert_messages
  JSON.parse(command("JavascriptAlertMessages"))
end

#allow_unknown_urlsObject



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_urlsObject



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

#bodyObject



42
43
44
# File 'lib/capybara/webkit/browser.rb', line 42

def body
  command("Body")
end

#clear_cookiesObject



251
252
253
# File 'lib/capybara/webkit/browser.rb', line 251

def clear_cookies
  command "ClearCookies"
end

#clear_prompt_textObject



186
187
188
# File 'lib/capybara/webkit/browser.rb', line 186

def clear_prompt_text
  command("ClearPromptText")
end

#clear_proxyObject



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, "The webkit_server process crashed!\n\n\#{exception.message}\n\nThis is a bug in capybara-webkit. For help with this crash, please visit:\n\nhttps://github.com/thoughtbot/capybara-webkit/wiki/Reporting-Crashes\n".strip)
end

#confirm_messagesObject



66
67
68
# File 'lib/capybara/webkit/browser.rb', line 66

def confirm_messages
  JSON.parse(command("JavascriptConfirmMessages"))
end

#console_messagesObject



50
51
52
53
54
# File 'lib/capybara/webkit/browser.rb', line 50

def console_messages
  JSON.parse(command("ConsoleMessages")).map do |message|
    message.inject({}) { |m,(k,v)| m.merge(k.to_sym => v) }
  end
end

#current_urlObject



78
79
80
# File 'lib/capybara/webkit/browser.rb', line 78

def current_url
  command("CurrentUrl")
end

#enable_loggingObject



14
15
16
# File 'lib/capybara/webkit/browser.rb', line 14

def enable_logging
  command "EnableLogging"
end

#error_messagesObject



56
57
58
59
60
# File 'lib/capybara/webkit/browser.rb', line 56

def error_messages
  console_messages.select do |message|
    message[: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_cookiesObject



255
256
257
# File 'lib/capybara/webkit/browser.rb', line 255

def get_cookies
  command("GetCookies").lines.map{ |line| line.strip }.select{ |line| !line.empty? }
end

#get_window_handleObject



136
137
138
# File 'lib/capybara/webkit/browser.rb', line 136

def get_window_handle
  command('GetWindowHandle')
end

#get_window_handlesObject



126
127
128
# File 'lib/capybara/webkit/browser.rb', line 126

def get_window_handles
  JSON.parse(command('GetWindowHandles'))
end

#go_backObject



272
273
274
# File 'lib/capybara/webkit/browser.rb', line 272

def go_back
  command("GoBack")
end

#go_forwardObject



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_errorsObject



94
95
96
# File 'lib/capybara/webkit/browser.rb', line 94

def ignore_ssl_errors
  command("IgnoreSslErrors")
end

#prompt_messagesObject



70
71
72
# File 'lib/capybara/webkit/browser.rb', line 70

def prompt_messages
  JSON.parse(command("JavascriptPromptMessages"))
end

#reject_confirm(options) ⇒ Object



154
155
156
# File 'lib/capybara/webkit/browser.rb', line 154

def reject_confirm(options)
  command("SetConfirmAction", "No", options[:text])
end

#reject_js_confirmsObject



158
159
160
# File 'lib/capybara/webkit/browser.rb', line 158

def reject_js_confirms
  command("SetConfirmAction", "No")
end

#reject_js_promptsObject



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(options)
  command("SetPromptAction", "No", options[: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_headersObject



74
75
76
# File 'lib/capybara/webkit/browser.rb', line 74

def response_headers
  JSON.parse(command("Headers"))
end


247
248
249
# File 'lib/capybara/webkit/browser.rb', line 247

def set_cookie(cookie)
  command "SetCookie", cookie
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(options = {})
  options = default_proxy_options.merge(options)
  command("SetProxy", options[:host], options[:port], options[:user], options[: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_codeObject



46
47
48
# File 'lib/capybara/webkit/browser.rb', line 46

def status_code
  command("Status").to_i
end

#timeoutObject



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

#titleObject



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

#versionObject



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_handleObject



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_handlesObject



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_openObject



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