diff options
Diffstat (limited to 'qa/qa/support/page/logging.rb')
-rw-r--r-- | qa/qa/support/page/logging.rb | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/qa/qa/support/page/logging.rb b/qa/qa/support/page/logging.rb index bc5ee645965..6dfb348a347 100644 --- a/qa/qa/support/page/logging.rb +++ b/qa/qa/support/page/logging.rb @@ -13,15 +13,15 @@ module QA end def refresh(skip_finished_loading_check: false) - log("refreshing #{current_url}") + log("refreshing #{current_url}", :info) super end def scroll_to(selector, text: nil) - msg = "scrolling to :#{Rainbow(selector).underline.bright}" + msg = "scrolling to :#{highlight_element(selector)}" msg += " with text: #{text}" if text - log(msg) + log(msg, :info) super end @@ -39,7 +39,7 @@ module QA element = super - log("found :#{Rainbow(name).underline.bright}") + log("found :#{name}") element end @@ -49,41 +49,41 @@ module QA elements = super - log("found #{elements.size} :#{Rainbow(name).underline.bright}") if elements + log("found #{elements.size} :#{name}") if elements elements end def check_element(name, click_by_js = nil) - log("checking :#{name}") + log("checking :#{highlight_element(name)}", :info) super end def uncheck_element(name, click_by_js = nil) - log("unchecking :#{name}") + log("unchecking :#{highlight_element(name)}", :info) super end def click_element_coordinates(name, **kwargs) - log(%Q(clicking the coordinates of :#{name})) + log(%(clicking the coordinates of :#{highlight_element(name)}), :info) super end def click_element(name, page = nil, **kwargs) - msg = ["clicking :#{Rainbow(name).underline.bright}"] + msg = ["clicking :#{highlight_element(name)}"] msg << ", expecting to be at #{page.class}" if page - msg << "with args #{kwargs}" - log(msg.compact.join(' ')) + log(msg.join(' '), :info) + log("with args #{kwargs}") super end def click_via_capybara(method, locator) - log("clicking via capybara using '#{method}(#{locator})'") + log("clicking via capybara using '#{method}(#{locator})'", :info) super end @@ -91,13 +91,13 @@ module QA def fill_element(name, content) masked_content = name.to_s.match?(/token|key|password/) ? '*****' : content - log(%Q(filling :#{name} with "#{masked_content}")) + log(%(filling :#{highlight_element(name)} with "#{masked_content}"), :info) super end def select_element(name, value) - log(%Q(selecting "#{value}" in :#{name})) + log(%(selecting "#{value}" in :#{highlight_element(name)}), :info) super end @@ -121,7 +121,7 @@ module QA def has_text?(text, **kwargs) found = super - log(%Q{has_text?('#{text}', wait: #{kwargs[:wait] || Capybara.default_max_wait_time}) returned #{found}}) + log(%(has_text?('#{text}', wait: #{kwargs[:wait] || Capybara.default_max_wait_time}) returned #{found})) found end @@ -129,7 +129,7 @@ module QA def has_no_text?(text, **kwargs) found = super - log(%Q{has_no_text?('#{text}', wait: #{kwargs[:wait] || Capybara.default_max_wait_time}) returned #{found}}) + log(%(has_no_text?('#{text}', wait: #{kwargs[:wait] || Capybara.default_max_wait_time}) returned #{found})) found end @@ -173,13 +173,26 @@ module QA private - def log(msg) - QA::Runtime::Logger.debug(msg) + # Log message + # + # @param [String] msg + # @param [Symbol] level + # @return [void] + def log(msg, level = :debug) + QA::Runtime::Logger.public_send(level, msg) + end + + # Highlight element for enhanced logging + # + # @param [String] element + # @return [String] + def highlight_element(element) + element.to_s.underline.bright end def log_has_element_or_not(method, name, found, **kwargs) - msg = ["#{method} :#{Rainbow(name).underline.bright}"] - msg << %Q(with text "#{kwargs[:text]}") if kwargs[:text] + msg = ["#{method} :#{name}"] + msg << %(with text "#{kwargs[:text]}") if kwargs[:text] msg << "class: #{kwargs[:class]}" if kwargs[:class] msg << "(wait: #{kwargs[:wait] || Capybara.default_max_wait_time})" msg << "returned: #{found}" |