lib/element.rb in gridium-1.1.4 vs lib/element.rb in gridium-1.1.6

- old
+ new

@@ -33,11 +33,11 @@ if stale? wait = Selenium::WebDriver::Wait.new :timeout => Gridium.config.element_timeout, :interval => 1 if Gridium.config.visible_elements_only wait.until { @element = displayed_element } else - wait.until { @element = @parent.find_element(@by, @locator); Log.debug("Finding element #{self}..."); @element.enabled? } + wait.until { @element = @parent.find_element(@by, @locator); Log.debug("[GRIDIUM::Element] Finding element #{self}..."); @element.enabled? } end end @element end @@ -55,18 +55,18 @@ if element.displayed? #removed check for element.enabled found_element = element; #this will always return the last displayed element end end if found_element.nil? - Log.debug "found #{elements.length} element(s) via #{@by} and #{@locator} and 0 are displayed" + Log.debug "[GRIDIUM::Element] found #{elements.length} element(s) via #{@by} and #{@locator} and 0 are displayed" end rescue StandardError => error - Log.debug("element.displayed_element rescued: #{error}") + Log.debug("[GRIDIUM::Element] element.displayed_element rescued: #{error}") if found_element - Log.warn("An element was found, but it was not displayed on the page. Gridium.config.visible_elements_only set to: #{Gridium.config.visible_elements_only} Element: #{self.to_s}") + Log.warn("[GRIDIUM::Element] An element was found, but it was not displayed on the page. Gridium.config.visible_elements_only set to: #{Gridium.config.visible_elements_only} Element: #{self.to_s}") else - Log.warn("Could not find Element: #{self.to_s}") + Log.warn("[GRIDIUM::Element] Could not find Element: #{self.to_s}") end end found_element end @@ -75,18 +75,18 @@ # Element Commands # # ================ # # soft failure, will not kill test immediately def verify(timeout: nil) - Log.debug('Verifying new element...') + Log.debug('[GRIDIUM::Element] Verifying new element...') timeout = Gridium.config.element_timeout if timeout.nil? ElementVerification.new(self, timeout) end # hard failure, will kill test immediately def wait_until(timeout: nil) - Log.debug('Waiting for new element...') + Log.debug('[GRIDIUM::Element] Waiting for new element...') timeout = Gridium.config.element_timeout if timeout.nil? ElementVerification.new(self, timeout, fail_test: true) end def attribute(name) @@ -100,18 +100,18 @@ def present? return element.enabled? rescue StandardError => error - Log.debug("element.present? is false because this error was rescued: #{error}") + Log.debug("[GRIDIUM::Element] element.present? is false because this error was rescued: #{error}") return false end def displayed? return element.displayed? rescue StandardError => error - Log.debug("element.displayed? is false because this error was rescued: #{error}") + Log.debug("[GRIDIUM::Element] element.displayed? is false because this error was rescued: #{error}") return false end def enabled? element.enabled? @@ -196,59 +196,59 @@ def location_once_scrolled_into_view element.location_once_scrolled_into_view end def hover_over - Log.debug("Hovering over element (#{self.to_s})...") + Log.debug("[GRIDIUM::Element] Hovering over element (#{self.to_s})...") # @driver.mouse.move_to(element) # Note: Doesn't work with Selenium 2.42 bindings for Firefox v31 # @driver.action.move_to(element).perform # @driver.mouse_over(@locator) if element.enabled? $verification_passes += 1 ElementExtensions.hover_over(self) # Javascript workaround to above issue else - Log.error('Cannot hover over element. Element is not present.') + Log.error('[GRIDIUM::Element] Cannot hover over element. Element is not present.') end end def hover_away - Log.debug("Hovering away from element (#{self.to_s})...") + Log.debug("[GRIDIUM::Element] Hovering away from element (#{self.to_s})...") if element.enabled? $verification_passes += 1 ElementExtensions.hover_away(self) # Javascript workaround to above issue else - Log.error('Cannot hover away from element. Element is not present.') + Log.error('[GRIDIUM::Element] Cannot hover away from element. Element is not present.') end end # Raw webdriver mouse over def mouse_over - Log.debug("Triggering mouse over for (#{self.to_s})...") + Log.debug("[GRIDIUM::Element] Triggering mouse over for (#{self.to_s})...") if element.enabled? $verification_passes += 1 ElementExtensions.mouse_over(self) else - Log.error('Cannot mouse over. Element is not present.') + Log.error('[GRIDIUM::Element] Cannot mouse over. Element is not present.') end end def scroll_into_view if element.enabled? $verification_passes += 1 ElementExtensions.scroll_to(self) else - Log.error('Cannot scroll element into view. Element is not present.') + Log.error('[GRIDIUM::Element] Cannot scroll element into view. Element is not present.') end end def trigger_onblur - Log.debug("Triggering onblur for (#{self.to_s})...") + Log.debug("[GRIDIUM::Element] Triggering onblur for (#{self.to_s})...") if element.enabled? $verification_passes += 1 ElementExtensions.trigger_onblur(self) else - Log.error('Cannot trigger onblur. Element is not present.') + Log.error('[GRIDIUM::Element] Cannot trigger onblur. Element is not present.') end end def size element.size @@ -278,11 +278,11 @@ # @param [String] locator # # @return [Element] element # def find_element(by, locator) - Log.debug('Finding element...') + Log.debug('[GRIDIUM::Element] Finding element...') Element.new("Child of #{@name}", by, locator, parent: @element) end # # Search for an elements within this element @@ -296,11 +296,11 @@ elements = element.find_elements(by, locator) elements.map {|_| Element.new("Child of #{@name}", by, locator, parent: @element)} end def save_element_screenshot - Log.debug ("Capturing screenshot of element...") + Log.debug ("[GRIDIUM::Element] Capturing screenshot of element...") self.scroll_into_view timestamp = Time.now.strftime("%Y_%m_%d__%H_%M_%S") name = self.name.gsub(' ', '_') screenshot_path = File.join($current_run_dir, "#{name}__#{timestamp}.png") @@ -322,32 +322,32 @@ end def compare_element_screenshot(base_image_path) #Returns TRUE if there are no differences, FALSE if there are begin - Log.debug("Loading Images for Comparison...") + Log.debug("[GRIDIUM::Element] Loading Images for Comparison...") images = [ ChunkyPNG::Image.from_file(base_image_path), ChunkyPNG::Image.from_file(@element_screenshot) ] #used to store image x,y diff diff = [] - Log.debug("Comparing Images...") + Log.debug("[GRIDIUM::Element] Comparing Images...") images.first.height.times do |y| images.first.row(y).each_with_index do |pixel, x| diff << [x,y] unless pixel == images.last[x,y] end end - Log.debug("Pixels total: #{images.first.pixels.length}") - Log.debug("Pixels changed: #{diff.length}") - Log.debug("Pixels changed: #{(diff.length.to_f / images.first.pixels.length) * 100}%") + Log.debug("[GRIDIUM::Element] Pixels total: #{images.first.pixels.length}") + Log.debug("[GRIDIUM::Element] Pixels changed: #{diff.length}") + Log.debug("[GRIDIUM::Element] Pixels changed: #{(diff.length.to_f / images.first.pixels.length) * 100}%") x, y = diff.map{|xy| xy[0]}, diff.map{|xy| xy[1]} if x.any? && y.any? - Log.debug("Differences Detected! Writing Diff Image...") + Log.debug("[GRIDIUM::Element] Differences Detected! Writing Diff Image...") name = self.name.gsub(' ', '_') #timestamp = Time.now.strftime("%Y_%m_%d__%H_%M_%S") element_screenshot_path = File.join($current_run_dir, "#{name}__diff_.png") images.last.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color(0,255,0)) images.last.save(element_screenshot_path) @@ -359,11 +359,11 @@ Log.error("There was a problem comparing element images. #{e.to_s}") end end def method_missing(method_sym, *arguments, &block) - Log.debug("called #{method_sym} on element #{@locator} by #{@by_type}") + Log.debug("[GRIDIUM::Element] called #{method_sym} on element #{@locator} by #{@by_type}") if @element.respond_to?(method_sym) @element.method(method_sym).call(*arguments, &block) else super end @@ -371,26 +371,26 @@ private def stale? return true if @element.nil? - @element.disabled? + @element.displayed? rescue StandardError => error - Log.debug("element.stale? is true because this error was rescued: #{error}") - Log.warn("Stale element detected.... #{self.to_s}") + Log.debug("[GRIDIUM::Element] element.stale? is true because this error was rescued: #{error}") + Log.warn("[GRIDIUM::Element] Stale element detected.... #{self.to_s}") return true end # # helper to clear input and put new text in # def _stomp_input_text(*args) - Log.debug("Clearing \"#{value}\" from element: (#{self})") + Log.debug("[GRIDIUM::Element] Clearing \"#{value}\" from element: (#{self})") element.clear sleep @text_padding_time - Log.debug("Typing: #{args} into element: (#{self}).") + Log.debug("[GRIDIUM::Element] Typing: #{args} into element: (#{self}).") element.send_keys(*args) sleep @text_padding_time end # @@ -398,10 +398,10 @@ # TODO: verify if text correct afterward, but need to be able to handle cases # of symbols like :space and :enter correctly # def field_empty_afterward?(*args) - Log.debug("Checking the field after sending #{args}, to see if it's empty") + Log.debug("[GRIDIUM::Element] Checking the field after sending #{args}, to see if it's empty") check_again = (has_characters? *args and no_symbols? *args) field_is_empty_but_should_not_be = (check_again and field_empty?) if field_is_empty_but_should_not_be raise "Browser Error: tried to input #{args} but found an empty string afterward: #{value}" end