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.
102
103
104
105
106
107
|
# File 'lib/capybara/driver/selenium_driver.rb', line 102
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.
90
91
92
|
# File 'lib/capybara/driver/selenium_driver.rb', line 90
def app
@app
end
|
#options ⇒ Object
Returns the value of attribute options.
90
91
92
|
# File 'lib/capybara/driver/selenium_driver.rb', line 90
def options
@options
end
|
#rack_server ⇒ Object
Returns the value of attribute rack_server.
90
91
92
|
# File 'lib/capybara/driver/selenium_driver.rb', line 90
def rack_server
@rack_server
end
|
Instance Method Details
#body ⇒ Object
117
118
119
|
# File 'lib/capybara/driver/selenium_driver.rb', line 117
def body
browser.page_source
end
|
#browser ⇒ Object
92
93
94
95
96
97
98
99
100
|
# File 'lib/capybara/driver/selenium_driver.rb', line 92
def browser
unless @browser
@browser = Selenium::WebDriver.for(options[:browser] || :firefox, options.reject{|key,val| key == :browser})
at_exit do
@browser.quit
end
end
@browser
end
|
#current_url ⇒ Object
121
122
123
|
# File 'lib/capybara/driver/selenium_driver.rb', line 121
def current_url
browser.current_url
end
|
#evaluate_script(script) ⇒ Object
135
136
137
|
# File 'lib/capybara/driver/selenium_driver.rb', line 135
def evaluate_script(script)
browser.execute_script "return #{script}"
end
|
#execute_script(script) ⇒ Object
131
132
133
|
# File 'lib/capybara/driver/selenium_driver.rb', line 131
def execute_script(script)
browser.execute_script script
end
|
#find(selector) ⇒ Object
125
126
127
|
# File 'lib/capybara/driver/selenium_driver.rb', line 125
def find(selector)
browser.find_elements(:xpath, selector).map { |node| Node.new(self, node) }
end
|
#reset! ⇒ Object
139
140
141
142
|
# File 'lib/capybara/driver/selenium_driver.rb', line 139
def reset!
@browser.manage.delete_all_cookies if @browser
end
|
#source ⇒ Object
113
114
115
|
# File 'lib/capybara/driver/selenium_driver.rb', line 113
def source
browser.page_source
end
|
#visit(path) ⇒ Object
109
110
111
|
# File 'lib/capybara/driver/selenium_driver.rb', line 109
def visit(path)
browser.navigate.to(url(path))
end
|
#wait? ⇒ Boolean
129
|
# File 'lib/capybara/driver/selenium_driver.rb', line 129
def wait?; true; end
|
#within_frame(frame_id) ⇒ Object
144
145
146
147
148
149
|
# File 'lib/capybara/driver/selenium_driver.rb', line 144
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
151
152
153
|
# File 'lib/capybara/driver/selenium_driver.rb', line 151
def within_window(handle, &blk)
browser.switch_to.window(handle, &blk)
end
|