summaryrefslogtreecommitdiff
path: root/qa/qa/support
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /qa/qa/support
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
downloadgitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'qa/qa/support')
-rw-r--r--qa/qa/support/api.rb24
-rw-r--r--qa/qa/support/json_formatter.rb54
-rw-r--r--qa/qa/support/page/logging.rb8
-rw-r--r--qa/qa/support/wait_for_requests.rb20
4 files changed, 101 insertions, 5 deletions
diff --git a/qa/qa/support/api.rb b/qa/qa/support/api.rb
index 3c46c039eae..08faacb6db3 100644
--- a/qa/qa/support/api.rb
+++ b/qa/qa/support/api.rb
@@ -77,6 +77,30 @@ module QA
error.response
end
+
+ def with_paginated_response_body(url)
+ loop do
+ response = get(url)
+
+ QA::Runtime::Logger.debug("Fetching page #{response.headers[:x_page]} of #{response.headers[:x_total_pages]}...")
+
+ yield parse_body(response)
+
+ next_link = pagination_links(response).find { |link| link[:rel] == 'next' }
+ break unless next_link
+
+ url = next_link[:url]
+ end
+ end
+
+ def pagination_links(response)
+ response.headers[:link].split(',').map do |link|
+ match = link.match(/\<(?<url>.*)\>\; rel=\"(?<rel>\w+)\"/)
+ break nil unless match
+
+ { url: match[:url], rel: match[:rel] }
+ end.compact
+ end
end
end
end
diff --git a/qa/qa/support/json_formatter.rb b/qa/qa/support/json_formatter.rb
new file mode 100644
index 00000000000..5d2a3e7b75f
--- /dev/null
+++ b/qa/qa/support/json_formatter.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+require 'rspec/core/formatters'
+
+module QA
+ module Support
+ class JsonFormatter < RSpec::Core::Formatters::JsonFormatter
+ RSpec::Core::Formatters.register self, :message, :dump_summary, :stop, :seed, :close
+
+ def dump_profile(profile)
+ # We don't currently use the profile info. This overrides the base
+ # implementation so that it's not included.
+ end
+
+ def stop(notification)
+ # Based on https://github.com/rspec/rspec-core/blob/main/lib/rspec/core/formatters/json_formatter.rb#L35
+ # But modified to include full details of multiple exceptions
+ @output_hash[:examples] = notification.examples.map do |example|
+ format_example(example).tap do |hash|
+ e = example.exception
+ if e
+ exceptions = e.respond_to?(:all_exceptions) ? e.all_exceptions : [e]
+ hash[:exceptions] = exceptions.map do |exception|
+ {
+ class: exception.class.name,
+ message: exception.message,
+ backtrace: exception.backtrace
+ }
+ end
+ end
+ end
+ end
+ end
+
+ private
+
+ def format_example(example)
+ {
+ id: example.id,
+ description: example.description,
+ full_description: example.full_description,
+ status: example.execution_result.status.to_s,
+ file_path: example.metadata[:file_path],
+ line_number: example.metadata[:line_number],
+ run_time: example.execution_result.run_time,
+ pending_message: example.execution_result.pending_message,
+ status_issue: example.metadata[:status_issue],
+ quarantine: example.metadata[:quarantine],
+ screenshot: example.metadata[:screenshot]
+ }
+ end
+ end
+ end
+end
diff --git a/qa/qa/support/page/logging.rb b/qa/qa/support/page/logging.rb
index 281e1b85cc3..ea0307e58b2 100644
--- a/qa/qa/support/page/logging.rb
+++ b/qa/qa/support/page/logging.rb
@@ -64,6 +64,12 @@ module QA
super
end
+ def click_element_coordinates(name)
+ log(%Q(clicking the coordinates of :#{name}))
+
+ super
+ end
+
def click_element(name, page = nil, **kwargs)
msg = ["clicking :#{name}"]
msg << ", expecting to be at #{page.class}" if page
@@ -120,7 +126,7 @@ module QA
found
end
- def finished_loading?
+ def finished_loading?(wait: QA::Support::Repeater::DEFAULT_MAX_WAIT_TIME)
log('waiting for loading to complete...')
now = Time.now
diff --git a/qa/qa/support/wait_for_requests.rb b/qa/qa/support/wait_for_requests.rb
index c58882a11ea..943d7d510df 100644
--- a/qa/qa/support/wait_for_requests.rb
+++ b/qa/qa/support/wait_for_requests.rb
@@ -5,20 +5,32 @@ module QA
module WaitForRequests
module_function
- def wait_for_requests
+ DEFAULT_MAX_WAIT_TIME = 60
+
+ def wait_for_requests(skip_finished_loading_check: false)
Waiter.wait_until(log: false) do
- finished_all_ajax_requests? && finished_all_axios_requests?
+ finished_all_ajax_requests? && finished_all_axios_requests? && (!skip_finished_loading_check ? finished_loading?(wait: 1) : true)
end
end
def finished_all_axios_requests?
- Capybara.page.evaluate_script('window.pendingRequests || 0').zero?
+ Capybara.page.evaluate_script('window.pendingRequests || 0').zero? # rubocop:disable Style/NumericPredicate
end
def finished_all_ajax_requests?
return true if Capybara.page.evaluate_script('typeof jQuery === "undefined"')
- Capybara.page.evaluate_script('jQuery.active').zero?
+ Capybara.page.evaluate_script('jQuery.active').zero? # rubocop:disable Style/NumericPredicate
+ end
+
+ def finished_loading?(wait: DEFAULT_MAX_WAIT_TIME)
+ # The number of selectors should be able to be reduced after
+ # migration to the new spinner is complete.
+ # https://gitlab.com/groups/gitlab-org/-/epics/956
+ # retry_on_exception added here due to `StaleElementReferenceError`. See: https://gitlab.com/gitlab-org/gitlab/-/issues/232485
+ Support::Retrier.retry_on_exception do
+ Capybara.page.has_no_css?('.gl-spinner, .fa-spinner, .spinner', wait: wait)
+ end
end
end
end