Class: Capybara::Driver::Selenium
- Inherits:
-
Base
- Object
- Base
- Capybara::Driver::Selenium
show all
- Defined in:
- lib/capybara/driver/selenium_driver.rb
Defined Under Namespace
Classes: Node
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#has_shortcircuit_timeout?, #response_headers, #status_code, #wait_until
Constructor Details
#initialize(app, options = {}) ⇒ Selenium
Returns a new instance of Selenium.
106
107
108
109
110
111
|
# File 'lib/capybara/driver/selenium_driver.rb', line 106
def initialize(app, options={})
@app = app
@options = options
@rack_server = Capybara::Server.new(@app)
@rack_server.boot if Capybara.run_server
end
|
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
94
95
96
|
# File 'lib/capybara/driver/selenium_driver.rb', line 94
def app
@app
end
|
#options ⇒ Object
Returns the value of attribute options.
94
95
96
|
# File 'lib/capybara/driver/selenium_driver.rb', line 94
def options
@options
end
|
#rack_server ⇒ Object
Returns the value of attribute rack_server.
94
95
96
|
# File 'lib/capybara/driver/selenium_driver.rb', line 94
def rack_server
@rack_server
end
|
Instance Method Details
#body ⇒ Object
121
122
123
|
# File 'lib/capybara/driver/selenium_driver.rb', line 121
def body
browser.page_source
end
|
#browser ⇒ Object
96
97
98
99
100
101
102
103
104
|
# File 'lib/capybara/driver/selenium_driver.rb', line 96
def browser
unless @browser
@browser = Selenium::WebDriver.for(options[:browser] || :firefox, options)
at_exit do
@browser.quit
end
end
@browser
end
|
#current_url ⇒ Object
125
126
127
|
# File 'lib/capybara/driver/selenium_driver.rb', line 125
def current_url
browser.current_url
end
|
#evaluate_script(script) ⇒ Object
139
140
141
|
# File 'lib/capybara/driver/selenium_driver.rb', line 139
def evaluate_script(script)
browser.execute_script "return #{script}"
end
|
#execute_script(script) ⇒ Object
135
136
137
|
# File 'lib/capybara/driver/selenium_driver.rb', line 135
def execute_script(script)
browser.execute_script script
end
|
#find(selector) ⇒ Object
129
130
131
|
# File 'lib/capybara/driver/selenium_driver.rb', line 129
def find(selector)
browser.find_elements(:xpath, selector).map { |node| Node.new(self, node) }
end
|
#reset! ⇒ Object
143
144
145
146
|
# File 'lib/capybara/driver/selenium_driver.rb', line 143
def reset!
@browser.manage.delete_all_cookies if @browser
end
|
#source ⇒ Object
117
118
119
|
# File 'lib/capybara/driver/selenium_driver.rb', line 117
def source
browser.page_source
end
|
#visit(path) ⇒ Object
113
114
115
|
# File 'lib/capybara/driver/selenium_driver.rb', line 113
def visit(path)
browser.navigate.to(url(path))
end
|
#wait? ⇒ Boolean
133
|
# File 'lib/capybara/driver/selenium_driver.rb', line 133
def wait?; true; end
|
#within_frame(frame_id) ⇒ Object
148
149
150
151
152
153
|
# File 'lib/capybara/driver/selenium_driver.rb', line 148
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(handle, &blk) ⇒ Object
155
156
157
|
# File 'lib/capybara/driver/selenium_driver.rb', line 155
def within_window(handle, &blk)
browser.switch_to.window(handle, &blk)
end
|