class Chemlab::Component

The base representation of any UI component.

Public Class Methods

perform() { |new| ... } click to toggle source

Perform actions against the given page @example

Component.perform do |component|
  component.do_something
end

@example

Component.perform(&:do_something)

@return The instance of Component used to perform the action

# File lib/chemlab/component.rb, line 21
def self.perform
  yield new if block_given?
end
public_elements() click to toggle source

Elements defined on the page @example

+text_field :username, id: 'username'+
Will be in form:
  {
    type: :text_field,
    name: :username,
    args: [ { id: 'username' } ]
  }

@return [Array]

# File lib/chemlab/component.rb, line 36
def public_elements
  @public_elements ||= []
end

Private Class Methods

evaluator() click to toggle source
# File lib/chemlab/component.rb, line 122
def self.evaluator
  @evaluator ||= DSL.new(self)
end

Public Instance Methods

visible?() click to toggle source

If this component is currently visible @return [Boolean] true if the defined elements in the library are present @note The page presence is determined by the elements defined on the page and their requirement

# File lib/chemlab/component.rb, line 88
def visible?
  missing_elements = [] + self.class.public_elements

  self.class.public_elements.each do |element|
    missing_elements.shift if has_element?(element[:type], element[:name], element[:args].first)
  end

  missing_elements.none?
end

Protected Instance Methods

has_element?(watir_method, name, locator = nil) click to toggle source

Check existence of an element on the page @note this method will not wait for the element @see [find_element] @api private @example

#has_element?(:text_field, :username) => returns false if the element is is not there
# File lib/chemlab/component.rb, line 151
def has_element?(watir_method, name, locator = nil)
  locator = { css: %([data-qa-selector="#{name}"]) } if locator.nil?

  Chemlab.configuration.browser.session.engine.public_send(watir_method, locator).present?
end

Private Instance Methods

find_element(watir_method, name, locator = nil, &block) click to toggle source

Find an element on the page @note this method will wait for the element to appear @see [has_element] @api private @example

#find_element(:text_field, :username) #=>
# File lib/chemlab/component.rb, line 135
def find_element(watir_method, name, locator = nil, &block)
  locator = { css: %([data-qa-selector="#{name}"]) } if locator.nil?

  return instance_exec(&block) if block_given?

  Chemlab.configuration.browser.session.engine.public_send(watir_method, locator).wait_until(&:exist?)
end