Commit 32da5296 authored by Sofia Vistas's avatar Sofia Vistas Committed by Ramya Authappan

Format QA logger and add colorised logs

parent 1ba3d52a
......@@ -20,6 +20,7 @@ gem 'parallel_tests', '~> 2.29'
gem 'rotp', '~> 3.1.0'
gem 'timecop', '~> 0.9.1'
gem 'parallel', '~> 1.19'
gem 'rainbow', '~> 3.0.0'
gem 'rspec-parameterized', '~> 0.4.2'
gem 'octokit', '~> 4.21'
gem 'webdrivers', '~> 5.0'
......
......@@ -8,6 +8,7 @@ module QA
class Base
include ApiFabricator
extend Capybara::DSL
using Rainbow
NoValueError = Class.new(RuntimeError)
......@@ -102,7 +103,7 @@ module QA
Runtime::Logger.debug do
msg = ["==#{'=' * parents.size}>"]
msg << "#{fabrication_http_method} a #{name}"
msg << "#{fabrication_http_method} a #{Rainbow(name).black.bg(:white)}"
msg << identifier
msg << "as a dependency of #{parents.last}" if parents.any?
msg << "via #{fabrication_method}"
......@@ -182,7 +183,7 @@ module QA
end
def visit!(skip_resp_code_check: false)
Runtime::Logger.debug(%(Visiting #{self.class.name} at "#{web_url}"))
Runtime::Logger.debug("Visiting #{Rainbow(self.class.name).black.bg(:white)} at #{web_url}")
# Just in case an async action is not yet complete
Support::WaitForRequests.wait_for_requests(skip_resp_code_check: skip_resp_code_check)
......
......@@ -17,7 +17,6 @@ module QA
end
def fabricate!
puts 'TODO: FABRICATE VIA UI'
end
def resource_web_url(resource)
......
......@@ -11,7 +11,6 @@ module QA
end
def fabricate!
puts 'TODO: FABRICATE VIA UI'
end
def resource_web_url(resource)
......
......@@ -65,6 +65,10 @@ module QA
ENV['QA_LOG_PATH'] || $stdout
end
def colorized_logs?
enabled?(ENV['COLORIZED_LOGS'], default: false)
end
# set to 'false' to have the browser run visibly instead of headless
def webdriver_headless?
if ENV.key?('CHROME_HEADLESS')
......
......@@ -2,11 +2,13 @@
require 'logger'
require 'forwardable'
require 'rainbow/refinement'
module QA
module Runtime
module Logger
extend SingleForwardable
using Rainbow
def_delegators :logger, :debug, :info, :warn, :error, :fatal, :unknown
......@@ -14,8 +16,16 @@ module QA
attr_writer :logger
def logger
Rainbow.enabled = Runtime::Env.colorized_logs?
@logger ||= ::Logger.new(Runtime::Env.log_destination).tap do |logger|
logger.level = Runtime::Env.debug? ? ::Logger::DEBUG : ::Logger::ERROR
logger.formatter = proc do |severity, datetime, progname, msg|
date_format = datetime.strftime("%Y-%m-%d %H:%M:%S")
"[date=#{date_format} from=QA Tests] #{severity.ljust(5)} -- ".yellow + "#{msg}\n"
end
end
end
end
......
......@@ -49,7 +49,7 @@ module QA
if account.empty?
raise "Failed to login to gcloud. No credentials provided in environment and no credentials found locally."
else
puts "gcloud account found. Using: #{account} for creating K8s cluster."
QA::Runtime::Logger.debug("gcloud account found. Using: #{account} for creating K8s cluster.")
end
end
end
......
......@@ -5,6 +5,7 @@ require 'open3'
module QA
module Service
module Shellout
using Rainbow
CommandError = Class.new(StandardError)
module_function
......@@ -14,7 +15,7 @@ module QA
# as a library - gitlab-org/gitlab-qa#94
#
def shell(command, stdin_data: nil, fail_on_exception: true)
puts "Executing `#{command}`"
QA::Runtime::Logger.info("Executing `#{command}`".cyan)
Open3.popen2e(*command) do |stdin, out, wait|
stdin.puts(stdin_data) if stdin_data
......
......@@ -4,6 +4,8 @@ module QA
module Support
module Page
module Logging
using Rainbow
def assert_no_element(name)
log("asserting no element :#{name}")
......@@ -17,7 +19,7 @@ module QA
end
def scroll_to(selector, text: nil)
msg = "scrolling to :#{selector}"
msg = "scrolling to :#{Rainbow(selector).underline.bright}"
msg += " with text: #{text}" if text
log(msg)
......@@ -37,7 +39,7 @@ module QA
element = super
log("found :#{name}") if element
log("found :#{Rainbow(name).underline.bright}")
element
end
......@@ -47,7 +49,7 @@ module QA
elements = super
log("found #{elements.size} :#{name}") if elements
log("found #{elements.size} :#{Rainbow(name).underline.bright}") if elements
elements
end
......@@ -71,7 +73,7 @@ module QA
end
def click_element(name, page = nil, **kwargs)
msg = ["clicking :#{name}"]
msg = ["clicking :#{Rainbow(name).underline.bright}"]
msg << ", expecting to be at #{page.class}" if page
msg << "with args #{kwargs}"
......@@ -170,7 +172,7 @@ module QA
end
def log_has_element_or_not(method, name, found, **kwargs)
msg = ["#{method} :#{name}"]
msg = ["#{method} :#{Rainbow(name).underline.bright}"]
msg << %Q(with text "#{kwargs[:text]}") if kwargs[:text]
msg << "class: #{kwargs[:class]}" if kwargs[:class]
msg << "(wait: #{kwargs[:wait] || Capybara.default_max_wait_time})"
......
# frozen_string_literal: true
require 'active_support/inflector'
require 'rainbow/refinement'
module QA
module Support
module Repeater
using Rainbow
DEFAULT_MAX_WAIT_TIME = 60
RepeaterConditionExceededError = Class.new(RuntimeError)
......@@ -39,7 +40,7 @@ module QA
QA::Runtime::Logger.debug(msg.join(' '))
end
QA::Runtime::Logger.debug("Attempt number #{attempts + 1}") if log && max_attempts && attempts > 0
QA::Runtime::Logger.debug("Attempt number #{attempts + 1}".bg(:yellow).black) if log && max_attempts && attempts > 0
result = yield
if result
......
......@@ -16,7 +16,7 @@ module QA
def run
Runtime::Scenario.define(:gitlab_address, address)
puts "Signing in and creating the default password for the root user if it's not set already..."
QA::Runtime::Logger.info("Signing in and creating the default password for the root user if it's not set already...")
QA::Runtime::Browser.visit(:gitlab, QA::Page::Main::Login)
Flow::Login.sign_in
......
......@@ -6,6 +6,7 @@ require 'securerandom'
require 'pathname'
require 'active_support/core_ext/hash'
require 'active_support/core_ext/object/blank'
require 'rainbow/refinement'
require_relative 'qa_deprecation_toolkit_env'
QaDeprecationToolkitEnv.configure!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment