class Mache::Page

The {Page} class wraps an HTML page with an application-specific API. You can extend it to define your own API for manipulating the pages of your web application.

@example

class WelcomePage < Mache::page
  element :main, "#main"
  component :nav, Nav, "#nav"
end

page = WelcomePage.new(path: "/welcome")
page.visit
page.current # true
page.main.text # lorem ipsum

Attributes

path[R]

The path where the page is located, without any domain information.

@return [String] the path string @example

"/welcome"
"/users/sign_in"

Public Class Methods

new(node: Capybara.current_session, path: nil) click to toggle source

Returns a new page object.

@param node [Capybara::Node] a Capybara node to attach to @param path [String] a path to where the page is located

# File lib/mache/page.rb, line 34
def initialize(node: Capybara.current_session, path: nil)
  @node = node
  @path = path
end
visit() click to toggle source

Creates a new page object and calls {#visit} on it.

@return [Page] a page object

# File lib/mache/page.rb, line 57
def self.visit
  new.visit
end

Public Instance Methods

current?() click to toggle source

Tests whether the page is current.

@return [Boolean] `true` if the page is current, `false` otherwise.

# File lib/mache/page.rb, line 50
def current?
  @node.current_path == path
end
visit() click to toggle source

Visits the page at its {#path}.

@return [Page] a page object

# File lib/mache/page.rb, line 42
def visit
  @node.visit(path)
  self
end