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
#cleanup!, #has_shortcircuit_timeout?, #response_headers, #status_code, #wait_until
Constructor Details
#initialize(app, options = {}) ⇒ Selenium
Returns a new instance of Selenium.
94
95
96
97
98
99
|
# File 'lib/capybara/driver/selenium_driver.rb', line 94
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.
82
83
84
|
# File 'lib/capybara/driver/selenium_driver.rb', line 82
def app
@app
end
|
#options ⇒ Object
Returns the value of attribute options.
82
83
84
|
# File 'lib/capybara/driver/selenium_driver.rb', line 82
def options
@options
end
|
#rack_server ⇒ Object
Returns the value of attribute rack_server.
82
83
84
|
# File 'lib/capybara/driver/selenium_driver.rb', line 82
def rack_server
@rack_server
end
|
Instance Method Details
#body ⇒ Object
109
110
111
|
# File 'lib/capybara/driver/selenium_driver.rb', line 109
def body
browser.page_source
end
|
#browser ⇒ Object
84
85
86
87
88
89
90
91
92
|
# File 'lib/capybara/driver/selenium_driver.rb', line 84
def browser
unless @browser
@browser = Selenium::WebDriver.for(options.delete(:browser) || :firefox, options)
at_exit do
@browser.quit
end
end
@browser
end
|
#current_url ⇒ Object
113
114
115
|
# File 'lib/capybara/driver/selenium_driver.rb', line 113
def current_url
browser.current_url
end
|
#evaluate_script(script) ⇒ Object
127
128
129
|
# File 'lib/capybara/driver/selenium_driver.rb', line 127
def evaluate_script(script)
browser.execute_script "return #{script}"
end
|
#execute_script(script) ⇒ Object
123
124
125
|
# File 'lib/capybara/driver/selenium_driver.rb', line 123
def execute_script(script)
browser.execute_script script
end
|
#find(selector) ⇒ Object
117
118
119
|
# File 'lib/capybara/driver/selenium_driver.rb', line 117
def find(selector)
browser.find_elements(:xpath, selector).map { |node| Node.new(self, node) }
end
|
#reset! ⇒ Object
131
132
133
134
|
# File 'lib/capybara/driver/selenium_driver.rb', line 131
def reset!
@browser.manage.delete_all_cookies if @browser
end
|
#source ⇒ Object
105
106
107
|
# File 'lib/capybara/driver/selenium_driver.rb', line 105
def source
browser.page_source
end
|
#visit(path) ⇒ Object
101
102
103
|
# File 'lib/capybara/driver/selenium_driver.rb', line 101
def visit(path)
browser.navigate.to(url(path))
end
|
#wait? ⇒ Boolean
121
|
# File 'lib/capybara/driver/selenium_driver.rb', line 121
def wait?; true; end
|
#within_frame(frame_id) ⇒ Object
136
137
138
139
140
141
|
# File 'lib/capybara/driver/selenium_driver.rb', line 136
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
143
144
145
|
# File 'lib/capybara/driver/selenium_driver.rb', line 143
def within_window(handle, &blk)
browser.switch_to.window(handle, &blk)
end
|