module Howitzer::Meta::Actions

Module with utility actions for elements

Public Instance Methods

highlight(*args, **options) click to toggle source

Highlights element with red border on the page @param args [Array] arguments for elements described with lambda locators @param options [Hash] original Capybara options. For details, see ‘Capybara::Node::Finders#all`

# 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) click to toggle source

Returns xpath for the element @param args [Array] arguments for elements described with lambda locators @param options [Hash] original Capybara options. For details, see ‘Capybara::Node::Finders#all` @return [String, nil]

# File lib/howitzer/meta/actions.rb, line 24
def xpath(*args, **options)
  capybara_element(*args, **options).try(:path)
end

Private Instance Methods

escape(xpath) click to toggle source
# File lib/howitzer/meta/actions.rb, line 30
def escape(xpath)
  xpath.gsub(/(['"])/, '\\\\\\1')
end