Class: Capybara::Selenium::Driver
- Inherits:
-
Driver::Base
show all
- Defined in:
- lib/capybara/selenium/driver.rb
Constant Summary
- DEFAULT_OPTIONS =
{
:resynchronize => true,
:resynchronization_timeout => 10,
:browser => :firefox
}
- SPECIAL_OPTIONS =
[:browser, :resynchronize, :resynchronization_timeout]
Instance Attribute Summary (collapse)
Instance Method Summary
(collapse)
#has_shortcircuit_timeout?, #response_headers, #status_code, #wait_until
Constructor Details
- (Driver) initialize(app, options = {})
25
26
27
28
29
30
|
# File 'lib/capybara/selenium/driver.rb', line 25
def initialize(app, options={})
@app = app
@options = DEFAULT_OPTIONS.merge(options)
@rack_server = Capybara::Server.new(@app)
@rack_server.boot if Capybara.run_server
end
|
Instance Attribute Details
- (Object) app
Returns the value of attribute app
11
12
13
|
# File 'lib/capybara/selenium/driver.rb', line 11
def app
@app
end
|
- (Object) options
Returns the value of attribute options
11
12
13
|
# File 'lib/capybara/selenium/driver.rb', line 11
def options
@options
end
|
- (Object) rack_server
Returns the value of attribute rack_server
11
12
13
|
# File 'lib/capybara/selenium/driver.rb', line 11
def rack_server
@rack_server
end
|
Instance Method Details
- (Object) body
40
41
42
|
# File 'lib/capybara/selenium/driver.rb', line 40
def body
browser.page_source
end
|
- (Object) browser
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/capybara/selenium/driver.rb', line 13
def browser
unless @browser
@browser = Selenium::WebDriver.for(options[:browser], options.reject { |key,val| SPECIAL_OPTIONS.include?(key) })
main = Process.pid
at_exit do
quit if Process.pid == main
end
end
@browser
end
|
- (Object) current_url
44
45
46
|
# File 'lib/capybara/selenium/driver.rb', line 44
def current_url
browser.current_url
end
|
- (Object) evaluate_script(script)
70
71
72
|
# File 'lib/capybara/selenium/driver.rb', line 70
def evaluate_script(script)
browser.execute_script "return #{script}"
end
|
- (Object) execute_script(script)
66
67
68
|
# File 'lib/capybara/selenium/driver.rb', line 66
def execute_script(script)
browser.execute_script script
end
|
- (Object) find(selector)
48
49
50
|
# File 'lib/capybara/selenium/driver.rb', line 48
def find(selector)
browser.find_elements(:xpath, selector).map { |node| Capybara::Selenium::Node.new(self, node) }
end
|
- (Object) find_window(selector)
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/capybara/selenium/driver.rb', line 95
def find_window( selector )
original_handle = browser.window_handle
browser.window_handles.each do |handle|
browser.switch_to.window handle
if( selector == browser.execute_script("return window.name") ||
browser.title.include?(selector) ||
browser.current_url.include?(selector) ||
(selector == handle) )
browser.switch_to.window original_handle
return handle
end
end
raise Capybara::ElementNotFound, "Could not find a window identified by #{selector}"
end
|
- (Object) quit
115
116
117
118
119
|
# File 'lib/capybara/selenium/driver.rb', line 115
def quit
@browser.quit
rescue Errno::ECONNREFUSED
end
|
- (Object) reset!
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/capybara/selenium/driver.rb', line 74
def reset!
if @browser
begin
@browser.manage.delete_all_cookies
rescue Selenium::WebDriver::Error::UnhandledError => e
end
@browser.navigate.to('about:blank')
end
end
|
- (Object) resynchronize
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/capybara/selenium/driver.rb', line 54
def resynchronize
if options[:resynchronize]
load_wait_for_ajax_support
yield
Capybara.timeout(options[:resynchronization_timeout], self, "failed to resynchronize, ajax request timed out") do
evaluate_script("!window.capybaraRequestsOutstanding")
end
else
yield
end
end
|
- (Object) source
36
37
38
|
# File 'lib/capybara/selenium/driver.rb', line 36
def source
browser.page_source
end
|
- (Object) visit(path)
32
33
34
|
# File 'lib/capybara/selenium/driver.rb', line 32
def visit(path)
browser.navigate.to(url(path))
end
|
- (Boolean) wait?
52
|
# File 'lib/capybara/selenium/driver.rb', line 52
def wait?; true; end
|
- (Object) within_frame(frame_id)
88
89
90
91
92
93
|
# File 'lib/capybara/selenium/driver.rb', line 88
def within_frame(frame_id)
old_window = browser.window_handle
browser.switch_to.frame(frame_id)
yield
browser.switch_to.window old_window
end
|
- (Object) within_window(selector, &blk)
110
111
112
113
|
# File 'lib/capybara/selenium/driver.rb', line 110
def within_window(selector, &blk)
handle = find_window( selector )
browser.switch_to.window(handle, &blk)
end
|