lib/kirchhoff/common_interface.rb in kirchhoff-0.0.2 vs lib/kirchhoff/common_interface.rb in kirchhoff-0.0.3

- old
+ new

@@ -1,40 +1,40 @@ module Kirchhoff module CommonInterface - def find selector - e = self.find_element(css: selector).tap do - Kirchhoff::Logger.call :info, "find #{selector}..." - end + def find selector, maybe: true, wait: true + e = wait ? self.waiter.until { weak_find(selector) } : weak_find(selector) + Kirchhoff::Logger.call :info, "find #{selector}..." + block_given? ? yield(e) : e - rescue Selenium::WebDriver::Error::NoSuchElementError - nil + rescue Selenium::WebDriver::Error::NoSuchElementError, Selenium::WebDriver::Error::TimeOutError + unless maybe + raise Selenium::WebDriver::Error::NoSuchElementError, "selector: #{selector}" + end end def multi_find selector - self.find_elements(css: selector).tap do |e| + weak_multi_find(selector).tap do Kirchhoff::Logger.call :info, "multi find #{selector}..." end end - def find_text text - e = self.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"}).tap do - Kirchhoff::Logger.call :info, "find text '#{text}'..." - end + def find_text text, maybe: true, wait: true + e = wait ? self.waiter.until { weak_find_text(text) } : weak_find_text(text) + Kirchhoff::Logger.call :info, "find text '#{text}'..." + block_given? ? yield(e) : e - rescue Selenium::WebDriver::Error::NoSuchElementError - nil + rescue Selenium::WebDriver::Error::NoSuchElementError, Selenium::WebDriver::Error::TimeOutError + unless maybe + raise Selenium::WebDriver::Error::NoSuchElementError, "text: #{text}" + end end def multi_find_text text - self.find_elements({xpath: "//*[text()[contains(.,\"#{text}\")]]"}).tap do |e| + weak_multi_find_text(text).tap do Kirchhoff::Logger.call :info, "multi find text '#{text}'..." end - end - - def to_html - attribute "outerHTML" end def to_nokogiri Nokogiri::HTML self.to_html end