Sha256: 29206cfcae4b01d9308bf0cbf4ed5e63b6365b100a6ef4c94e511a7903a62c3b

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

module Howitzer
  module Meta
    # Module with utility actions for elements
    module Actions
      # 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`
      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

      # 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]
      def xpath(*args, **options)
        capybara_element(*args, **options).try(:path)
      end

      private

      def escape(xpath)
        xpath.gsub(/(['"])/, '\\\\\\1')
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
howitzer-2.6.1 lib/howitzer/meta/actions.rb
howitzer-2.6.0 lib/howitzer/meta/actions.rb
howitzer-2.5.0 lib/howitzer/meta/actions.rb
howitzer-2.4.0 lib/howitzer/meta/actions.rb
howitzer-2.3.0 lib/howitzer/meta/actions.rb