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.
-
#rack_server ⇒ Object
readonly
Returns the value of attribute rack_server.
Class Method Summary collapse
-
.driver ⇒ Client
An instance of Akephalos::Client.
Instance Method Summary collapse
-
#body ⇒ String
The page’s modified source.
-
#browser ⇒ Object
The browser.
-
#cleanup! ⇒ Object
deprecated
Deprecated.
This method is deprecated in Capybara’s master branch. Use #reset! instead.
-
#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) ⇒ Akephalos
constructor
A new instance of Akephalos.
-
#page ⇒ Object
The current page.
-
#reset! ⇒ Object
Clear all cookie session data.
-
#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, &block) ⇒ Object
Execute the given block within the context of a specified frame.
Constructor Details
#initialize(app) ⇒ Akephalos
Returns a new instance of Akephalos.
149 150 151 152 153 |
# File 'lib/akephalos/capybara.rb', line 149 def initialize(app) @app = app @rack_server = ::Server.new(@app) @rack_server.boot if .run_server end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
142 143 144 |
# File 'lib/akephalos/capybara.rb', line 142 def app @app end |
#rack_server ⇒ Object (readonly)
Returns the value of attribute rack_server.
142 143 144 |
# File 'lib/akephalos/capybara.rb', line 142 def rack_server @rack_server end |
Class Method Details
.driver ⇒ Client
Returns an instance of Akephalos::Client.
145 146 147 |
# File 'lib/akephalos/capybara.rb', line 145 def self.driver @driver ||= Akephalos::Client.new end |
Instance Method Details
#body ⇒ String
Returns the page’s modified source.
168 169 170 |
# File 'lib/akephalos/capybara.rb', line 168 def body page.modified_source end |
#browser ⇒ Object
Returns the browser.
241 242 243 |
# File 'lib/akephalos/capybara.rb', line 241 def browser self.class.driver end |
#cleanup! ⇒ Object
This method is deprecated in Capybara’s master branch. Use #reset! instead.
Clear all cookie session data.
195 196 197 |
# File 'lib/akephalos/capybara.rb', line 195 def cleanup! reset! end |
#cookies ⇒ Object
Returns the session cookies.
246 247 248 |
# File 'lib/akephalos/capybara.rb', line 246 def browser. end |
#current_url ⇒ String
Returns the page’s current URL.
205 206 207 |
# File 'lib/akephalos/capybara.rb', line 205 def current_url page.current_url end |
#evaluate_script(script) ⇒ Object
Execute JavaScript against the current page and return the results.
231 232 233 |
# File 'lib/akephalos/capybara.rb', line 231 def evaluate_script(script) page.evaluate_script script end |
#execute_script(script) ⇒ nil
Execute JavaScript against the current page, discarding any return value.
223 224 225 |
# File 'lib/akephalos/capybara.rb', line 223 def execute_script(script) page.execute_script script end |
#find(selector) ⇒ Array<Node>
Search for nodes which match the given XPath selector.
213 214 215 216 217 |
# File 'lib/akephalos/capybara.rb', line 213 def find(selector) nodes = [] page.find(selector).each { |node| nodes << Node.new(self, node) } nodes end |
#page ⇒ Object
Returns the current page.
236 237 238 |
# File 'lib/akephalos/capybara.rb', line 236 def page browser.page end |
#reset! ⇒ Object
Clear all cookie session data.
200 201 202 |
# File 'lib/akephalos/capybara.rb', line 200 def reset! .clear end |
#response_headers ⇒ Hash{String => String}
Returns the page’s response headers.
173 174 175 |
# File 'lib/akephalos/capybara.rb', line 173 def response_headers page.response_headers end |
#source ⇒ String
Returns the page’s original source.
163 164 165 |
# File 'lib/akephalos/capybara.rb', line 163 def source page.source end |
#status_code ⇒ Integer
Returns the response’s status code.
178 179 180 |
# File 'lib/akephalos/capybara.rb', line 178 def status_code page.status_code end |
#user_agent ⇒ String
Returns the current user agent string.
251 252 253 |
# File 'lib/akephalos/capybara.rb', line 251 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.
260 261 262 |
# File 'lib/akephalos/capybara.rb', line 260 def user_agent=(user_agent) browser.user_agent = user_agent end |
#visit(path) ⇒ Object
Visit the given path in the browser.
158 159 160 |
# File 'lib/akephalos/capybara.rb', line 158 def visit(path) browser.visit(url(path)) end |
#wait ⇒ false
Disable waiting in Capybara, since waiting is handled directly by Akephalos.
268 269 270 |
# File 'lib/akephalos/capybara.rb', line 268 def wait false end |
#within_frame(frame_id, &block) ⇒ Object
Execute the given block within the context of a specified frame.
186 187 188 189 190 |
# File 'lib/akephalos/capybara.rb', line 186 def within_frame(frame_id, &block) unless page.within_frame(frame_id, &block) raise ::ElementNotFound, "Unable to find frame with id '#{frame_id}'" end end |