Class: Capybara::Driver::Akephalos

Inherits:
Base
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Akephalos

Returns a new instance of Akephalos.



158
159
160
161
162
# File 'lib/akephalos/capybara.rb', line 158

def initialize(app)
  @app = app
  @rack_server = Capybara::Server.new(@app)
  @rack_server.boot if Capybara.run_server
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



151
152
153
# File 'lib/akephalos/capybara.rb', line 151

def app
  @app
end

#rack_serverObject (readonly)

Returns the value of attribute rack_server.



151
152
153
# File 'lib/akephalos/capybara.rb', line 151

def rack_server
  @rack_server
end

Class Method Details

.driverClient

Returns an instance of Akephalos::Client.

Returns:

  • (Client)

    an instance of Akephalos::Client



154
155
156
# File 'lib/akephalos/capybara.rb', line 154

def self.driver
  @driver ||= Akephalos::Client.new
end

Instance Method Details

#bodyString

Returns the page's modified source.

Returns:

  • (String)

    the page's modified source



177
178
179
# File 'lib/akephalos/capybara.rb', line 177

def body
  page.modified_source
end

#browserObject

Returns the browser.

Returns:

  • the browser



250
251
252
# File 'lib/akephalos/capybara.rb', line 250

def browser
  self.class.driver
end

#cleanup!Object

Deprecated.

This method is deprecated in Capybara's master branch. Use #reset! instead.

Clear all cookie session data.



204
205
206
# File 'lib/akephalos/capybara.rb', line 204

def cleanup!
  reset!
end

#cookiesObject

Returns the session cookies.

Returns:

  • the session cookies



255
256
257
# File 'lib/akephalos/capybara.rb', line 255

def cookies
  browser.cookies
end

#current_urlString

Returns the page's current URL.

Returns:

  • (String)

    the page's current URL



214
215
216
# File 'lib/akephalos/capybara.rb', line 214

def current_url
  page.current_url
end

#evaluate_script(script) ⇒ Object

Execute JavaScript against the current page and return the results.

Parameters:

  • script (String)

    the JavaScript to be executed

Returns:

  • the result of the JavaScript



240
241
242
# File 'lib/akephalos/capybara.rb', line 240

def evaluate_script(script)
  page.evaluate_script script
end

#execute_script(script) ⇒ nil

Execute JavaScript against the current page, discarding any return value.

Parameters:

  • script (String)

    the JavaScript to be executed

Returns:

  • (nil)


232
233
234
# File 'lib/akephalos/capybara.rb', line 232

def execute_script(script)
  page.execute_script script
end

#find(selector) ⇒ Array<Node>

Search for nodes which match the given XPath selector.

Parameters:

  • selector (String)

    XPath query

Returns:

  • (Array<Node>)

    the matched nodes



222
223
224
225
226
# File 'lib/akephalos/capybara.rb', line 222

def find(selector)
  nodes = []
  page.find(selector).each { |node| nodes << Node.new(self, node) }
  nodes
end

#pageObject

Returns the current page.

Returns:

  • the current page



245
246
247
# File 'lib/akephalos/capybara.rb', line 245

def page
  browser.page
end

#reset!Object

Clear all cookie session data.



209
210
211
# File 'lib/akephalos/capybara.rb', line 209

def reset!
  cookies.clear
end

#response_headersHash{String => String}

Returns the page's response headers.

Returns:

  • (Hash{String => String})

    the page's response headers



182
183
184
# File 'lib/akephalos/capybara.rb', line 182

def response_headers
  page.response_headers
end

#sourceString

Returns the page's original source.

Returns:

  • (String)

    the page's original source



172
173
174
# File 'lib/akephalos/capybara.rb', line 172

def source
  page.source
end

#status_codeInteger

Returns the response's status code.

Returns:

  • (Integer)

    the response's status code



187
188
189
# File 'lib/akephalos/capybara.rb', line 187

def status_code
  page.status_code
end

#user_agentString

Returns the current user agent string.

Returns:

  • (String)

    the current user agent string



260
261
262
# File 'lib/akephalos/capybara.rb', line 260

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.

Parameters:

  • user_agent (:default)

    the default user agent

  • user_agent (String)

    the user agent string to use



269
270
271
# File 'lib/akephalos/capybara.rb', line 269

def user_agent=(user_agent)
  browser.user_agent = user_agent
end

#visit(path) ⇒ Object

Visit the given path in the browser.

Parameters:

  • path (String)

    relative path to visit



167
168
169
# File 'lib/akephalos/capybara.rb', line 167

def visit(path)
  browser.visit(url(path))
end

#waitfalse

Disable waiting in Capybara, since waiting is handled directly by Akephalos.

Returns:

  • (false)


277
278
279
# File 'lib/akephalos/capybara.rb', line 277

def wait
  false
end

#within_frame(frame_id, &block) ⇒ Object

Execute the given block within the context of a specified frame.

Parameters:

  • frame_id (String)

    the frame's id

Raises:

  • (Capybara::ElementNotFound)

    if the frame is not found



195
196
197
198
199
# File 'lib/akephalos/capybara.rb', line 195

def within_frame(frame_id, &block)
  unless page.within_frame(frame_id, &block)
    raise Capybara::ElementNotFound, "Unable to find frame with id '#{frame_id}'"
  end
end