Class: Capybara::Driver::Akephalos
- Inherits:
-
Base
- Object
- Base
- Capybara::Driver::Akephalos
- Defined in:
- lib/akephalos/capybara.rb
Overview
Driver class exposed to Capybara. It implements Capybara’s full driver API, and is the entry point for interaction between the test suites and HtmlUnit.
This class and Capybara::Driver::Akephalos::Node
are written to run on both MRI and JRuby, and is agnostic whether the Akephalos::Client instance is used directly or over DRb.
Defined Under Namespace
Classes: Node
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#rack_server ⇒ Object
readonly
Returns the value of attribute rack_server.
Instance Method Summary collapse
-
#body ⇒ String
page.modified_source will return a string with html entities converted into the unicode equivalent but the string will be marked as ASCII-8BIT which causes conversion issues so we force the encoding to UTF-8 (ruby 1.9 only).
-
#browser ⇒ Object
The browser.
-
#cleanup! ⇒ Object
deprecated
Deprecated.
This method is deprecated in Capybara’s master branch. Use #reset! instead.
-
#confirm_dialog(confirm = true, &block) ⇒ Object
Confirm or cancel the dialog, returning the text of the dialog.
-
#cookies ⇒ Object
The session cookies.
-
#current_url ⇒ String
The page’s current URL.
-
#evaluate_script(script) ⇒ Object
Execute JavaScript against the current page and return the results.
-
#execute_script(script) ⇒ nil
Execute JavaScript against the current page, discarding any return value.
-
#find(selector) ⇒ Array<Node>
Search for nodes which match the given XPath selector.
-
#initialize(app, options = {}) ⇒ Akephalos
constructor
Creates a new instance of the Akephalos Driver for Capybara.
-
#page ⇒ Object
The current page.
-
#reset! ⇒ Object
Reset session.
-
#response_headers ⇒ Hash{String => String}
The page’s response headers.
-
#source ⇒ String
The page’s original source.
-
#status_code ⇒ Integer
The response’s status code.
-
#user_agent ⇒ String
The current user agent string.
-
#user_agent=(user_agent) ⇒ Object
Set the User-Agent header for this session.
-
#visit(path) ⇒ Object
Visit the given path in the browser.
-
#wait ⇒ false
Disable waiting in Capybara, since waiting is handled directly by Akephalos.
-
#within_frame(frame_id_or_index, &block) ⇒ Object
Execute the given block within the context of a specified frame.
Constructor Details
#initialize(app, options = {}) ⇒ Akephalos
Creates a new instance of the Akephalos Driver for Capybara. The driver is registered with Capybara by a name, so that it can be chosen when Capybara’s javascript_driver is changed. By default, Akephalos is registered like this:
Capybara.register_driver :akephalos do |app|
Capybara::Akephalos::Driver.new(
app,
:browser => :firefox_3_6,
:validate_scripts => true
)
end
193 194 195 196 197 198 |
# File 'lib/akephalos/capybara.rb', line 193 def initialize(app, = {}) @app = app @options = @rack_server = Capybara::Server.new(@app) @rack_server.boot if Capybara.run_server end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
165 166 167 |
# File 'lib/akephalos/capybara.rb', line 165 def app @app end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
165 166 167 |
# File 'lib/akephalos/capybara.rb', line 165 def @options end |
#rack_server ⇒ Object (readonly)
Returns the value of attribute rack_server.
165 166 167 |
# File 'lib/akephalos/capybara.rb', line 165 def rack_server @rack_server end |
Instance Method Details
#body ⇒ String
page.modified_source will return a string with html entities converted into the unicode equivalent but the string will be marked as ASCII-8BIT which causes conversion issues so we force the encoding to UTF-8 (ruby 1.9 only)
218 219 220 221 222 223 224 225 226 |
# File 'lib/akephalos/capybara.rb', line 218 def body body_source = page.modified_source if body_source.respond_to?(:force_encoding) body_source.force_encoding("UTF-8") else body_source end end |
#browser ⇒ Object
Returns the browser.
305 306 307 |
# File 'lib/akephalos/capybara.rb', line 305 def browser @browser ||= Akephalos::Client.new(@options) end |
#cleanup! ⇒ Object
This method is deprecated in Capybara’s master branch. Use #reset! instead.
Clear all cookie session data.
252 253 254 |
# File 'lib/akephalos/capybara.rb', line 252 def cleanup! reset! end |
#confirm_dialog(confirm = true, &block) ⇒ Object
Confirm or cancel the dialog, returning the text of the dialog
264 265 266 |
# File 'lib/akephalos/capybara.rb', line 264 def confirm_dialog(confirm = true, &block) browser.confirm_dialog(confirm, &block) end |
#cookies ⇒ Object
Returns the session cookies.
310 311 312 |
# File 'lib/akephalos/capybara.rb', line 310 def browser. end |
#current_url ⇒ String
Returns the page’s current URL.
269 270 271 |
# File 'lib/akephalos/capybara.rb', line 269 def current_url page.current_url end |
#evaluate_script(script) ⇒ Object
Execute JavaScript against the current page and return the results.
295 296 297 |
# File 'lib/akephalos/capybara.rb', line 295 def evaluate_script(script) page.evaluate_script script end |
#execute_script(script) ⇒ nil
Execute JavaScript against the current page, discarding any return value.
287 288 289 |
# File 'lib/akephalos/capybara.rb', line 287 def execute_script(script) page.execute_script script end |
#find(selector) ⇒ Array<Node>
Search for nodes which match the given XPath selector.
277 278 279 280 281 |
# File 'lib/akephalos/capybara.rb', line 277 def find(selector) nodes = [] page.find(selector).each { |node| nodes << Node.new(self, node) } nodes end |
#page ⇒ Object
Returns the current page.
300 301 302 |
# File 'lib/akephalos/capybara.rb', line 300 def page browser.page end |
#reset! ⇒ Object
Reset session
257 258 259 260 261 |
# File 'lib/akephalos/capybara.rb', line 257 def reset! .clear browser.close_all_windows() browser.visit('about:blank') end |
#response_headers ⇒ Hash{String => String}
Returns the page’s response headers.
229 230 231 |
# File 'lib/akephalos/capybara.rb', line 229 def response_headers page.response_headers end |
#source ⇒ String
Returns the page’s original source.
208 209 210 |
# File 'lib/akephalos/capybara.rb', line 208 def source page.source end |
#status_code ⇒ Integer
Returns the response’s status code.
234 235 236 |
# File 'lib/akephalos/capybara.rb', line 234 def status_code page.status_code end |
#user_agent ⇒ String
Returns the current user agent string.
315 316 317 |
# File 'lib/akephalos/capybara.rb', line 315 def user_agent browser.user_agent end |
#user_agent=(user_agent) ⇒ Object
Set the User-Agent header for this session. If :default is given, the User-Agent header will be reset to the default browser’s user agent.
324 325 326 |
# File 'lib/akephalos/capybara.rb', line 324 def user_agent=(user_agent) browser.user_agent = user_agent end |
#visit(path) ⇒ Object
Visit the given path in the browser.
203 204 205 |
# File 'lib/akephalos/capybara.rb', line 203 def visit(path) browser.visit(url(path)) end |
#wait ⇒ false
Disable waiting in Capybara, since waiting is handled directly by Akephalos.
332 333 334 |
# File 'lib/akephalos/capybara.rb', line 332 def wait false end |
#within_frame(frame_id_or_index, &block) ⇒ Object
Execute the given block within the context of a specified frame.
242 243 244 245 246 247 |
# File 'lib/akephalos/capybara.rb', line 242 def within_frame(frame_id_or_index, &block) result = page.within_frame(frame_id_or_index, &block) unless page.within_frame(frame_id_or_index, &block) raise Capybara::ElementNotFound, "Unable to find frame with id '#{frame_id_or_index}'" end end |