Module: Howitzer::Meta::Actions

Included in:
Element, Iframe, Section
Defined in:
lib/howitzer/meta/actions.rb

Overview

Module with utility actions for elements

Instance Method Summary collapse

Instance Method Details

#highlight(*args, **options) ⇒ Object

Highlights element with red border on the page

Parameters:

  • args (Array)

    arguments for elements described with lambda locators

  • options (Hash)

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



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/howitzer/meta/actions.rb', line 8

def highlight(*args, **options)
  if xpath(*args, **options).blank?
    Howitzer::Log.debug("Element #{name} not found on the page")
    return
  end
  element = escape(xpath(*args, **options))
  context.execute_script(
    "document.evaluate('#{element}', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)." \
    'singleNodeValue.style.border = "thick solid red"'
  )
end

#xpath(*args, **options) ⇒ String?

Returns xpath for the element

Parameters:

  • args (Array)

    arguments for elements described with lambda locators

  • options (Hash)

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

Returns:

  • (String, nil)


24
25
26
# File 'lib/howitzer/meta/actions.rb', line 24

def xpath(*args, **options)
  capybara_element(*args, **options).try(:path)
end