Class: Capybara::Selenium::Driver
Constant Summary
collapse
- DEFAULT_OPTIONS =
{
:resynchronize => false,
: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
#initialize(app, options = {}) ⇒ Driver
Returns a new instance of Driver.
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
11
12
13
|
# File 'lib/capybara/selenium/driver.rb', line 11
def app
@app
end
|
#options ⇒ Object
Returns the value of attribute options.
11
12
13
|
# File 'lib/capybara/selenium/driver.rb', line 11
def options
@options
end
|
#rack_server ⇒ Object
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
#body ⇒ Object
43
44
45
|
# File 'lib/capybara/selenium/driver.rb', line 43
def body
browser.page_source
end
|
#browser ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# 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
@exit_status = $!.status if $!.is_a?(SystemExit)
quit if Process.pid == main
exit @exit_status if @exit_status end
end
@browser
end
|
#current_url ⇒ Object
47
48
49
|
# File 'lib/capybara/selenium/driver.rb', line 47
def current_url
browser.current_url
end
|
#evaluate_script(script) ⇒ Object
73
74
75
|
# File 'lib/capybara/selenium/driver.rb', line 73
def evaluate_script(script)
browser.execute_script "return #{script}"
end
|
#execute_script(script) ⇒ Object
69
70
71
|
# File 'lib/capybara/selenium/driver.rb', line 69
def execute_script(script)
browser.execute_script script
end
|
#find(selector) ⇒ Object
51
52
53
|
# File 'lib/capybara/selenium/driver.rb', line 51
def find(selector)
browser.find_elements(:xpath, selector).map { |node| Capybara::Selenium::Node.new(self, node) }
end
|
#find_window(selector) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/capybara/selenium/driver.rb', line 98
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
|
#invalid_element_errors ⇒ Object
124
125
126
|
# File 'lib/capybara/selenium/driver.rb', line 124
def invalid_element_errors
[Selenium::WebDriver::Error::ObsoleteElementError]
end
|
#quit ⇒ Object
118
119
120
121
122
|
# File 'lib/capybara/selenium/driver.rb', line 118
def quit
@browser.quit
rescue Errno::ECONNREFUSED
end
|
#reset! ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/capybara/selenium/driver.rb', line 77
def reset!
if @browser
begin
@browser.manage.delete_all_cookies
rescue Selenium::WebDriver::Error::UnhandledError => e
end
@browser.navigate.to('about:blank')
end
end
|
#resynchronize ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/capybara/selenium/driver.rb', line 57
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
|
#source ⇒ Object
39
40
41
|
# File 'lib/capybara/selenium/driver.rb', line 39
def source
browser.page_source
end
|
#visit(path) ⇒ Object
35
36
37
|
# File 'lib/capybara/selenium/driver.rb', line 35
def visit(path)
browser.navigate.to(url(path))
end
|
#wait? ⇒ Boolean
55
|
# File 'lib/capybara/selenium/driver.rb', line 55
def wait?; true; end
|
#within_frame(frame_id) ⇒ Object
91
92
93
94
95
96
|
# File 'lib/capybara/selenium/driver.rb', line 91
def within_frame(frame_id)
old_window = browser.window_handle
browser.switch_to.frame(frame_id)
yield
browser.switch_to.window old_window
end
|
#within_window(selector, &blk) ⇒ Object
113
114
115
116
|
# File 'lib/capybara/selenium/driver.rb', line 113
def within_window(selector, &blk)
handle = find_window( selector )
browser.switch_to.window(handle, &blk)
end
|