Class: Capybara::Webkit::Driver

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Driver.



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

def initialize(app, options={})
  @app = app
  @options = options
  @rack_server = Capybara::Server.new(@app)
  @rack_server.boot if Capybara.run_server
  @browser = options[:browser] || Browser.new(Connection.new(options))
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



12
13
14
# File 'lib/capybara/webkit/driver.rb', line 12

def browser
  @browser
end

Instance Method Details

#bodyObject



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

def body
  browser.body
end

#console_messagesObject



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

def console_messages
  browser.console_messages
end

#cookiesObject



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

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

#current_urlObject



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

def current_url
  browser.current_url
end

#enable_loggingObject



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

def enable_logging
  browser.enable_logging
end

#error_messagesObject



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

def error_messages
  browser.error_messages
end

#evaluate_script(script) ⇒ Object



59
60
61
# File 'lib/capybara/webkit/driver.rb', line 59

def evaluate_script(script)
  browser.evaluate_script script
end

#execute_script(script) ⇒ Object



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

def execute_script(script)
  value = browser.execute_script script
  value.empty? ? nil : value
end

#find(query) ⇒ Object



38
39
40
# File 'lib/capybara/webkit/driver.rb', line 38

def find(query)
  browser.find(query).map { |native| Node.new(self, native) }
end

#has_shortcircuit_timeout?Boolean

Returns:

  • (Boolean)


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

def has_shortcircuit_timeout?
  false
end

#header(key, value) ⇒ Object



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

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

#invalid_element_errorsObject



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

def invalid_element_errors
  []
end

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



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

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

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

#requested_urlObject



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

def requested_url
  browser.requested_url
end

#reset!Object



117
118
119
# File 'lib/capybara/webkit/driver.rb', line 117

def reset!
  browser.reset!
end

#resize_window(width, height) ⇒ Object



79
80
81
# File 'lib/capybara/webkit/driver.rb', line 79

def resize_window(width, height)
  browser.resize_window(width, height)
end

#response_headersObject



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

def response_headers
  browser.response_headers
end

#server_portObject



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

def server_port
  @rack_server.port
end

#sourceObject



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

def source
  browser.source
end

#status_codeObject



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

def status_code
  browser.status_code
end

#visit(path) ⇒ Object



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

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

#wait?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/capybara/webkit/driver.rb', line 110

def wait?
  true
end

#wait_until(*args) ⇒ Object



114
115
# File 'lib/capybara/webkit/driver.rb', line 114

def wait_until(*args)
end

#window_handleObject



106
107
108
# File 'lib/capybara/webkit/driver.rb', line 106

def window_handle
  browser.get_window_handle
end

#window_handlesObject



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

def window_handles
  browser.get_window_handles
end

#within_frame(frame_id_or_index) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/capybara/webkit/driver.rb', line 83

def within_frame(frame_id_or_index)
  browser.frame_focus(frame_id_or_index)
  begin
    yield
  ensure
    browser.frame_focus
  end
end

#within_window(selector) ⇒ Object



92
93
94
95
96
97
98
99
100
# File 'lib/capybara/webkit/driver.rb', line 92

def within_window(selector)
  current_window = window_handle
  browser.window_focus(selector)
  begin
    yield
  ensure
    browser.window_focus(current_window)
  end
end