Class: Howitzer::Meta::Element

Inherits:
Object
  • Object
show all
Includes:
Actions
Defined in:
lib/howitzer/meta/element.rb

Overview

This class represents element entity within howitzer meta information interface

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Actions

#highlight, #xpath

Constructor Details

#initialize(name, context) ⇒ Element

Creates new meta element with meta information and utility actions

Parameters:

  • name (String)

    name of the element

  • context (Howitzer::Web::Page)

    page element belongs to


11
12
13
14
# File 'lib/howitzer/meta/element.rb', line 11

def initialize(name, context)
  @name = name
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.


5
6
7
# File 'lib/howitzer/meta/element.rb', line 5

def context
  @context
end

#nameObject (readonly)

Returns the value of attribute name.


5
6
7
# File 'lib/howitzer/meta/element.rb', line 5

def name
  @name
end

Instance Method Details

#capybara_element(*args, wait: 0, **options) ⇒ Capybara::Node::Element?

Finds element on the page and returns as a capybara element

Parameters:

  • args (Array)

    arguments for elements described with lambda locators

  • options (Hash)

    original Capybara options. For details, see `Capybara::Node::Finders#all`

  • wait (Integer) (defaults to: 0)

    wait time for element search

Returns:

  • (Capybara::Node::Element, nil)

33
34
35
36
37
# File 'lib/howitzer/meta/element.rb', line 33

def capybara_element(*args, wait: 0, **options)
  context.send("#{name}_element", *args, **options.merge(match: :first, wait: wait))
rescue Capybara::ElementNotFound
  nil
end

#capybara_elements(*args, **options) ⇒ Array

Finds all instances of element on the page and returns them as array of capybara elements

Parameters:

  • args (Array)

    arguments for elements described with lambda locators

  • options (Hash)

    original Capybara options. For details, see `Capybara::Node::Finders#all`

Returns:

  • (Array)

20
21
22
23
24
25
26
# File 'lib/howitzer/meta/element.rb', line 20

def capybara_elements(*args, **options)
  if options.present?
    context.send("#{name}_elements", *args, **options)
  else
    context.send("#{name}_elements", *args)
  end
end