Class: Mache::Page

Inherits:
Node
  • Object
show all
Defined in:
lib/mache/page.rb

Overview

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.

Examples:


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

Instance Attribute Summary collapse

Attributes inherited from Node

#node

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#empty?, #method_missing

Methods included from DSL

included

Constructor Details

#initialize(node: Capybara.current_session, path: nil) ⇒ Page

Returns a new page object.

Parameters:

  • node (Capybara::Node) (defaults to: Capybara.current_session)

    a Capybara node to attach to

  • path (String) (defaults to: nil)

    a path to where the page is located



34
35
36
37
# File 'lib/mache/page.rb', line 34

def initialize(node: Capybara.current_session, path: nil)
  @node = node
  @path = path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mache::Node

Instance Attribute Details

#pathString (readonly)

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

Examples:

"/welcome"
"/users/sign_in"

Returns:

  • (String)

    the path string



28
29
30
# File 'lib/mache/page.rb', line 28

def path
  @path
end

Class Method Details

.visitPage

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

Returns:

  • (Page)

    a page object



57
58
59
# File 'lib/mache/page.rb', line 57

def self.visit
  new.visit
end

Instance Method Details

#current?Boolean

Tests whether the page is current.

Returns:

  • (Boolean)

    ‘true` if the page is current, `false` otherwise.



50
51
52
# File 'lib/mache/page.rb', line 50

def current?
  @node.current_path == path
end

#visitPage

Visits the page at its #path.

Returns:

  • (Page)

    a page object



42
43
44
45
# File 'lib/mache/page.rb', line 42

def visit
  @node.visit(path)
  self
end