Class: Chemlab::Page

Inherits:
Component show all
Defined in:
lib/chemlab/page.rb,
lib/chemlab/cli/stubber.rb

Overview

For each page that extends Chemlab::Page, run the stubber

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Component

perform, public_elements, #visible?

Class Method Details

.inherited(subclass) ⇒ Object



31
32
33
34
35
# File 'lib/chemlab/cli/stubber.rb', line 31

def self.inherited(subclass)
  print subclass

  Stubber.libraries << subclass
end

Instance Method Details

#on_page?Boolean

Check that the current Path segment of the URL matches the Path of the page

Examples:

class Page
  path '/test'
end

Page.perform do |page|
  page.visit
  expect(page).to be_on_page #=> passes if the path segment of the browser URL matches /test
end

Returns:

  • (Boolean)

    true if the path segment matches



24
25
26
27
28
29
# File 'lib/chemlab/page.rb', line 24

def on_page?
  URI(Chemlab.configuration.browser.url).path&.match?(self.class.path)
rescue TypeError
  # it's likely there is no path because of the page using the data protocol e.g.: "data:,"
  false
end

#visitObject

Visit the given page, specified by path ‘/the_path’



9
10
11
# File 'lib/chemlab/page.rb', line 9

def visit
  Runtime::Browser.navigate_to(self.class)
end