module SmartDriver::CommonInterface

Public Instance Methods

find(selector) { |e| ... } click to toggle source
# File lib/smart_driver/common_interface.rb, line 3
def find(selector)
  self.find_element(css: selector).tap do |e|
    logging :info, "find #{selector}..."
    yield(e) if block_given?
  end
end
find_text(text) { |e| ... } click to toggle source
# File lib/smart_driver/common_interface.rb, line 16
def find_text(text)
  self.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"}).tap do |e|
    logging :info, "find text '#{text}'..."
    yield(e) if block_given?
  end
end
finds(selector) click to toggle source
# File lib/smart_driver/common_interface.rb, line 10
def finds(selector)
  self.find_elements(css: selector).tap do |es|
    logging :info, "finds #{selector}..."
  end
end
finds_text(text) click to toggle source
# File lib/smart_driver/common_interface.rb, line 23
def finds_text(text)
  self.find_elements({xpath: "//*[text()[contains(.,\"#{text}\")]]"}).tap do |es|
    logging :info, "finds text '#{text}'..."
  end
end
has?(selector) click to toggle source
# File lib/smart_driver/common_interface.rb, line 29
def has?(selector)
  self.find_element(css: selector)
  true
rescue Selenium::WebDriver::Error::NoSuchElementError
  false
end
has_text?(text) click to toggle source
# File lib/smart_driver/common_interface.rb, line 36
def has_text?(text)
  self.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"})
  true
rescue Selenium::WebDriver::Error::NoSuchElementError
  false
end
to_html() click to toggle source
# File lib/smart_driver/common_interface.rb, line 43
def to_html
  attribute("outerHTML")
end

Private Instance Methods

logging(sym, text) click to toggle source
# File lib/smart_driver/common_interface.rb, line 48
def logging(sym, text)
  label = case sym
  when :info then "INFO"
  when :fail then "FAIL"
  end
  puts "[#{label}] #{text}"
end