Class: Capybara::Webkit::Driver

Inherits:
Driver::Base
  • Object
show all
Defined in:
lib/capybara/webkit/driver.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Driver

Returns a new instance of Driver.


12
13
14
15
16
17
18
# File 'lib/capybara/webkit/driver.rb', line 12

def initialize(app, options={})
  @app = app
  @options = options.dup
  @options[:server] ||= Server.new(options)
  @browser = options[:browser] || Browser.new(Connection.new(@options))
  apply_options
end

Instance Method Details

#accept_js_confirms!Object


207
208
209
210
211
# File 'lib/capybara/webkit/driver.rb', line 207

def accept_js_confirms!
  warn '[DEPRECATION] Capybara::Webkit::Driver#accept_js_confirms! ' \
    'is deprecated. Please use Capybara::Session#accept_confirm instead.'
  @browser.accept_js_confirms
end

#accept_js_prompts!Object


219
220
221
222
223
# File 'lib/capybara/webkit/driver.rb', line 219

def accept_js_prompts!
  warn '[DEPRECATION] Capybara::Webkit::Driver#accept_js_prompts! ' \
    'is deprecated. Please use Capybara::Session#accept_prompt instead.'
  @browser.accept_js_prompts
end

#accept_modal(type, options = {}) ⇒ Object


253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/capybara/webkit/driver.rb', line 253

def accept_modal(type, options={})
  options = modal_action_options_for_browser(options)

  case type
  when :confirm
    id = @browser.accept_confirm(options)
  when :prompt
    id = @browser.accept_prompt(options)
  else
    id = @browser.accept_alert(options)
  end

  yield

  find_modal(type, id, options)
end

#alert_messagesObject


107
108
109
110
111
# File 'lib/capybara/webkit/driver.rb', line 107

def alert_messages
  warn '[DEPRECATION] Capybara::Webkit::Driver#alert_messages ' \
    'is deprecated. Please use Capybara::Session#accept_alert instead.'
  @browser.alert_messages
end

#allow_unknown_urlsObject


40
41
42
43
# File 'lib/capybara/webkit/driver.rb', line 40

def allow_unknown_urls
  deprecate_and_replace_with_config "allow_unknown_urls"
  @browser.allow_url("*")
end

#allow_url(url) ⇒ Object


25
26
27
28
# File 'lib/capybara/webkit/driver.rb', line 25

def allow_url(url)
  deprecate_and_replace_with_config "allow_url", "allow_url(#{url.inspect})"
  @browser.allow_url(url)
end

#authenticate(username, password) ⇒ Object


338
339
340
# File 'lib/capybara/webkit/driver.rb', line 338

def authenticate(username, password)
  @browser.authenticate(username, password)
end

#block_unknown_urlsObject


35
36
37
38
# File 'lib/capybara/webkit/driver.rb', line 35

def block_unknown_urls
  deprecate_and_replace_with_config "block_unknown_urls"
  @browser.block_unknown_urls
end

#block_url(url) ⇒ Object


30
31
32
33
# File 'lib/capybara/webkit/driver.rb', line 30

def block_url(url)
  deprecate_and_replace_with_config "block_url", "block_url(#{url.inspect})"
  @browser.block_url(url)
end

#browserObject


355
356
357
358
# File 'lib/capybara/webkit/driver.rb', line 355

def browser
  warn "[DEPRECATION] Capybara::Webkit::Driver#browser is deprecated."
  @browser
end

#clear_cookiesObject


317
318
319
# File 'lib/capybara/webkit/driver.rb', line 317

def clear_cookies
  @browser.clear_cookies
end

#close_window(selector) ⇒ Object


199
200
201
# File 'lib/capybara/webkit/driver.rb', line 199

def close_window(selector)
  @browser.window_close(selector)
end

#confirm_messagesObject


113
114
115
116
117
118
# File 'lib/capybara/webkit/driver.rb', line 113

def confirm_messages
  warn '[DEPRECATION] Capybara::Webkit::Driver#confirm_messages ' \
    'is deprecated. Please use Capybara::Session#accept_confirm ' \
    'or Capybara::Session#dismiss_confirm instead.'
  @browser.confirm_messages
end

#console_messagesObject


99
100
101
# File 'lib/capybara/webkit/driver.rb', line 99

def console_messages
  @browser.console_messages
end

#cookiesObject


309
310
311
# File 'lib/capybara/webkit/driver.rb', line 309

def cookies
  @cookie_jar ||= CookieJar.new(@browser)
end

#current_urlObject


45
46
47
# File 'lib/capybara/webkit/driver.rb', line 45

def current_url
  @browser.current_url
end

#current_window_handleObject


191
192
193
# File 'lib/capybara/webkit/driver.rb', line 191

def current_window_handle
  @browser.get_window_handle
end

#dismiss_js_confirms!Object


213
214
215
216
217
# File 'lib/capybara/webkit/driver.rb', line 213

def dismiss_js_confirms!
  warn '[DEPRECATION] Capybara::Webkit::Driver#dismiss_js_confirms! ' \
    'is deprecated. Please use Capybara::Session#dismiss_confirm instead.'
  @browser.reject_js_confirms
end

#dismiss_js_prompts!Object


225
226
227
228
229
# File 'lib/capybara/webkit/driver.rb', line 225

def dismiss_js_prompts!
  warn '[DEPRECATION] Capybara::Webkit::Driver#dismiss_js_prompts! ' \
    'is deprecated. Please use Capybara::Session#dismiss_prompt instead.'
  @browser.reject_js_prompts
end

#dismiss_modal(type, options = {}) ⇒ Object


270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/capybara/webkit/driver.rb', line 270

def dismiss_modal(type, options={})
  options = modal_action_options_for_browser(options)

  case type
  when :confirm
    id = @browser.reject_confirm(options)
  else
    id = @browser.reject_prompt(options)
  end

  yield

  find_modal(type, id, options)
end

#enable_loggingObject


20
21
22
23
# File 'lib/capybara/webkit/driver.rb', line 20

def enable_logging
  deprecate_and_replace_with_config "enable_logging", "debug = true"
  @browser.enable_logging
end

#error_messagesObject


103
104
105
# File 'lib/capybara/webkit/driver.rb', line 103

def error_messages
  @browser.error_messages
end

#evaluate_async_script(script, *args) ⇒ Object


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

def evaluate_async_script(script, *args)
  result = @browser.evaluate_async_script(script, *encode_args(args))
  decode_result(result)
end

#evaluate_script(script, *args) ⇒ Object


89
90
91
92
# File 'lib/capybara/webkit/driver.rb', line 89

def evaluate_script(script, *args)
  result = @browser.evaluate_script(script, *encode_args(args))
  decode_result(result)
end

#execute_script(script, *args) ⇒ Object


79
80
81
82
83
84
85
86
87
# File 'lib/capybara/webkit/driver.rb', line 79

def execute_script(script, *args)
  value = @browser.execute_script(script, *encode_args(args))

  if value.empty?
    nil
  else
    value
  end
end

#find_css(selector) ⇒ Object


61
62
63
64
65
# File 'lib/capybara/webkit/driver.rb', line 61

def find_css(selector)
  @browser.
    find_css(selector).
    map { |native| Node.new(self, native, @browser) }
end

#find_xpath(xpath) ⇒ Object Also known as: find


53
54
55
56
57
# File 'lib/capybara/webkit/driver.rb', line 53

def find_xpath(xpath)
  @browser.
    find_xpath(xpath).
    map { |native| Node.new(self, native, @browser) }
end

#go_backObject


241
242
243
# File 'lib/capybara/webkit/driver.rb', line 241

def go_back
  @browser.go_back
end

#go_forwardObject


245
246
247
# File 'lib/capybara/webkit/driver.rb', line 245

def go_forward
  @browser.go_forward
end

#has_shortcircuit_timeout?Boolean

Returns:

  • (Boolean)

298
299
300
# File 'lib/capybara/webkit/driver.rb', line 298

def has_shortcircuit_timeout?
  false
end

#header(key, value) ⇒ Object


71
72
73
# File 'lib/capybara/webkit/driver.rb', line 71

def header(key, value)
  @browser.header(key, value)
end

#htmlObject


67
68
69
# File 'lib/capybara/webkit/driver.rb', line 67

def html
  @browser.body
end

#invalid_element_errorsObject


321
322
323
324
# File 'lib/capybara/webkit/driver.rb', line 321

def invalid_element_errors
  [Capybara::Webkit::ClickFailed,
   Capybara::Webkit::NodeNotAttachedError]
end

#js_prompt_input=(value) ⇒ Object


231
232
233
234
235
236
237
238
239
# File 'lib/capybara/webkit/driver.rb', line 231

def js_prompt_input=(value)
  warn '[DEPRECATION] Capybara::Webkit::Driver#js_prompt_input= ' \
    'is deprecated. Please use Capybara::Session#accept_prompt instead.'
  if value.nil?
    @browser.clear_prompt_text
  else
    @browser.set_prompt_text_to(value)
  end
end

#maximize_window(selector) ⇒ Object


203
204
205
# File 'lib/capybara/webkit/driver.rb', line 203

def maximize_window(selector)
  @browser.window_maximize(selector)
end

#needs_server?Boolean

Returns:

  • (Boolean)

289
290
291
# File 'lib/capybara/webkit/driver.rb', line 289

def needs_server?
  true
end

#no_such_window_errorObject


326
327
328
# File 'lib/capybara/webkit/driver.rb', line 326

def no_such_window_error
  Capybara::Webkit::NoSuchWindowError
end

#open_new_windowObject


195
196
197
# File 'lib/capybara/webkit/driver.rb', line 195

def open_new_window
  @browser.window_open
end

#prompt_messagesObject


120
121
122
123
124
125
# File 'lib/capybara/webkit/driver.rb', line 120

def prompt_messages
  warn '[DEPRECATION] Capybara::Webkit::Driver#prompt_messages ' \
    'is deprecated. Please use Capybara::Session#accept_prompt ' \
    'or Capybara::Session#dismiss_prompt instead.'
  @browser.prompt_messages
end

#refreshObject


249
250
251
# File 'lib/capybara/webkit/driver.rb', line 249

def refresh
  @browser.refresh
end

#reset!Object


293
294
295
296
# File 'lib/capybara/webkit/driver.rb', line 293

def reset!
  @browser.reset!
  apply_options
end

#resize_window(width, height) ⇒ Object


135
136
137
138
139
# File 'lib/capybara/webkit/driver.rb', line 135

def resize_window(width, height)
  warn '[DEPRECATION] Capybara::Webkit::Driver#resize_window ' \
    'is deprecated. Please use Capybara::Window#resize_to instead.'
  resize_window_to(current_window_handle, width, height)
end

#resize_window_to(handle, width, height) ⇒ Object


141
142
143
# File 'lib/capybara/webkit/driver.rb', line 141

def resize_window_to(handle, width, height)
  @browser.window_resize(handle, width, height)
end

#response_headersObject


127
128
129
# File 'lib/capybara/webkit/driver.rb', line 127

def response_headers
  @browser.response_headers
end

#save_screenshot(path, options = {}) ⇒ Object


302
303
304
305
306
307
# File 'lib/capybara/webkit/driver.rb', line 302

def save_screenshot(path, options={})
  options[:width]  ||= 1000
  options[:height] ||= 10

  @browser.render path, options[:width], options[:height]
end

313
314
315
# File 'lib/capybara/webkit/driver.rb', line 313

def set_cookie(cookie)
  @browser.set_cookie(cookie)
end

#status_codeObject


131
132
133
# File 'lib/capybara/webkit/driver.rb', line 131

def status_code
  @browser.status_code
end

#switch_to_frame(frame) ⇒ Object


158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/capybara/webkit/driver.rb', line 158

def switch_to_frame(frame)
  case frame
  when :top
    begin
      loop { @browser.frame_focus }
    rescue Capybara::Webkit::InvalidResponseError => e
      raise unless e.message =~ /Already at parent frame/
    end
  when :parent
    @browser.frame_focus
  else
    @browser.frame_focus(frame)
  end
end

#switch_to_window(selector) ⇒ Object


183
184
185
# File 'lib/capybara/webkit/driver.rb', line 183

def switch_to_window(selector)
  @browser.window_focus(selector)
end

#timeoutObject


342
343
344
345
# File 'lib/capybara/webkit/driver.rb', line 342

def timeout
  deprecate_and_replace_with_config "timeout"
  @browser.timeout
end

#timeout=(timeout) ⇒ Object


347
348
349
350
351
352
353
# File 'lib/capybara/webkit/driver.rb', line 347

def timeout=(timeout)
  deprecate_and_replace_with_config(
    "timeout=",
    "timeout = #{timeout.inspect}"
  )
  @browser.timeout = timeout
end

#titleObject


75
76
77
# File 'lib/capybara/webkit/driver.rb', line 75

def title
  @browser.title
end

#versionObject


330
331
332
333
334
335
336
# File 'lib/capybara/webkit/driver.rb', line 330

def version
  [
    "Capybara: #{Capybara::VERSION}",
    "capybara-webkit: #{Capybara::Driver::Webkit::VERSION}",
    @browser.version
  ].join("\n")
end

#visit(path) ⇒ Object


49
50
51
# File 'lib/capybara/webkit/driver.rb', line 49

def visit(path)
  @browser.visit(path)
end

#wait?Boolean

Returns:

  • (Boolean)

285
286
287
# File 'lib/capybara/webkit/driver.rb', line 285

def wait?
  true
end

#window_handlesObject


187
188
189
# File 'lib/capybara/webkit/driver.rb', line 187

def window_handles
  @browser.get_window_handles
end

#window_size(handle) ⇒ Object


145
146
147
# File 'lib/capybara/webkit/driver.rb', line 145

def window_size(handle)
  @browser.window_size(handle)
end

#within_frame(selector) ⇒ Object


149
150
151
152
153
154
155
156
# File 'lib/capybara/webkit/driver.rb', line 149

def within_frame(selector)
  @browser.frame_focus(selector)
  begin
    yield
  ensure
    @browser.frame_focus
  end
end

#within_window(selector) ⇒ Object


173
174
175
176
177
178
179
180
181
# File 'lib/capybara/webkit/driver.rb', line 173

def within_window(selector)
  current_window = current_window_handle
  switch_to_window(selector)
  begin
    yield
  ensure
    @browser.window_focus(current_window)
  end
end