Sha256: bbfefb0d62e6346fe14595cad423ccb4b0b917854aef3a58d1f34d0d02122cea

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

class SmartDriver
  module CommonInterface
    def find(selector)
      logging :info, "find #{selector}..."
      @__driver__.find_element(css: selector)
    rescue Selenium::WebDriver::Error::NoSuchElementError
      logging :fail, "#{selector} cannot be found"
      nil
    end

    def finds(selector)
      logging :info, "finds #{selector}..."
      @__driver__.find_elements(css: selector)
    rescue Selenium::WebDriver::Error::NoSuchElementError
      logging :fail, "#{selector} cannot be found"
      nil
    end

    def find_text(text)
      logging :info, "find text '#{text}'..."
      @__driver__.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"})
    rescue Selenium::WebDriver::Error::NoSuchElementError
      logging :fail, "text '#{text}' cannot be found"
      nil
    end

    def finds_text(text)
      logging :info, "finds text '#{text}'..."
      @__driver__.find_elements({xpath: "//*[text()[contains(.,\"#{text}\")]]"})
    rescue Selenium::WebDriver::Error::NoSuchElementError
      logging :fail, "text #{text} cannot be found"
      nil
    end

    def to_html
      attribute("outerHTML")
    end

    private
      def logging(sym, text)
        label = case sym
        when :info then "INFO"
        when :fail then "FAIL"
        end
        puts "[#{label}] #{text}"
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
smart_driver-1.1.1 lib/smart_driver/common_interface.rb
smart_driver-1.1.0 lib/smart_driver/common_interface.rb