Class: Chemlab::Runtime::Browser

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/chemlab/runtime/browser.rb

Overview

The browser configurator

Defined Under Namespace

Classes: Session

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(browser_options) ⇒ Browser

Returns a new instance of Browser.



16
17
18
19
# File 'lib/chemlab/runtime/browser.rb', line 16

def initialize(browser_options)
  @browser_options = browser_options
  @session = Session.new(browser_options)
end

Instance Attribute Details

#browser_optionsObject (readonly)

Returns the value of attribute browser_options.



12
13
14
# File 'lib/chemlab/runtime/browser.rb', line 12

def browser_options
  @browser_options
end

#sessionObject

Returns the value of attribute session.



11
12
13
# File 'lib/chemlab/runtime/browser.rb', line 11

def session
  @session
end

Class Method Details

Navigate to a given Page library

Examples:

Given:
  module TheLibrary
    def self.base_url
      'https://example.com'
    end
    class ThePage < Chemlab::Page
      path '/path'
    end
  end

Chemlab::Runtime::Browser.navigate_to(TheLibrary::ThePage) #=> Navigates to https://example.com/path
Given:
  Chemlab.configure do |chemlab|
    chemlab.base_url = 'https://example.com'
  end

  class ThePage < Chemlab::Page
    path '/'
  end

Chemlab::Runtime::Browser.navigate_to(ThePage) #=> Navigates to https://example.com/path

Parameters:

  • page_class (Class<Chemlab::Page>)

    the class of the Page to navigate to



47
48
49
50
51
52
53
# File 'lib/chemlab/runtime/browser.rb', line 47

def self.navigate_to(page_class)
  unless page_class&.name.respond_to?(:root_module) && page_class.name.root_module.respond_to?(:base_url)
    return Chemlab.configuration.browser.navigate_to(Chemlab.configuration.base_url + page_class.path)
  end

  Chemlab.configuration.browser.navigate_to(File.join(page_class.name.root_module.base_url, page_class.path))
end

Instance Method Details

Navigate to a Path

Examples:

Chemlab.configuration.browser.navigate_to('/path') #=> /path

Parameters:

  • path (String)

    the path to navigate to, relative to the base_url

Returns:

  • (String)

    the path that was navigated to



60
61
62
63
# File 'lib/chemlab/runtime/browser.rb', line 60

def navigate_to(path)
  @session ||= Chemlab.configuration.browser.session
  @session.engine.goto(path.to_s)
end

#to_sObject

The options used to create the browser session



66
67
68
# File 'lib/chemlab/runtime/browser.rb', line 66

def to_s
  @browser_options.to_s
end