Commit 8fc0d79a authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'qa-shl-wait-for-requests' into 'master'

Add ajax wait for requests

Closes #55286

See merge request gitlab-org/gitlab!22291
parents 9ced482f d58847b7
......@@ -490,6 +490,7 @@ module QA
autoload :Dates, 'qa/support/dates'
autoload :Waiter, 'qa/support/waiter'
autoload :Retrier, 'qa/support/retrier'
autoload :WaitForRequests, 'qa/support/wait_for_requests'
end
end
......
......@@ -49,13 +49,11 @@ module QA
def approve_license(name)
click_license(name)
click_element(:approve_license_button)
wait_for_animated_element(:license_management_modal)
end
def blacklist_license(name)
click_license(name)
click_element(:blacklist_license_button)
wait_for_animated_element(:license_management_modal)
end
end
end
......
......@@ -8,6 +8,7 @@ module QA
prepend Support::Page::Logging if Runtime::Env.debug?
include Capybara::DSL
include Scenario::Actable
include Support::WaitForRequests
extend Validatable
extend SingleForwardable
......@@ -21,6 +22,8 @@ module QA
def refresh
page.refresh
wait_for_requests
end
def wait(max: 60, interval: 0.1, reload: true)
......@@ -42,6 +45,8 @@ module QA
end
def scroll_to(selector, text: nil)
wait_for_requests
page.execute_script <<~JS
var elements = Array.from(document.querySelectorAll('#{selector}'));
var text = '#{text}';
......@@ -74,6 +79,8 @@ module QA
end
def find_element(name, **kwargs)
wait_for_requests
find(element_selector_css(name), kwargs)
end
......@@ -82,6 +89,8 @@ module QA
end
def all_elements(name, **kwargs)
wait_for_requests
all(element_selector_css(name), **kwargs)
end
......@@ -120,6 +129,8 @@ module QA
end
def has_element?(name, **kwargs)
wait_for_requests
wait = kwargs[:wait] ? kwargs[:wait] && kwargs.delete(:wait) : Capybara.default_max_wait_time
text = kwargs[:text] ? kwargs[:text] && kwargs.delete(:text) : nil
......@@ -127,6 +138,8 @@ module QA
end
def has_no_element?(name, **kwargs)
wait_for_requests
wait = kwargs[:wait] ? kwargs[:wait] && kwargs.delete(:wait) : Capybara.default_max_wait_time
text = kwargs[:text] ? kwargs[:text] && kwargs.delete(:text) : nil
......@@ -134,18 +147,24 @@ module QA
end
def has_text?(text, wait: Capybara.default_max_wait_time)
wait_for_requests
page.has_text?(text, wait: wait)
end
def has_no_text?(text)
wait_for_requests
page.has_no_text? text
end
def has_normalized_ws_text?(text, wait: Capybara.default_max_wait_time)
page.has_text?(text.gsub(/\s+/, " "), wait: wait)
has_text?(text.gsub(/\s+/, " "), wait: wait)
end
def finished_loading?
wait_for_requests
# 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
......@@ -153,6 +172,8 @@ module QA
end
def finished_loading_block?
wait_for_requests
has_no_css?('.fa-spinner.block-loading', wait: Capybara.default_max_wait_time)
end
......@@ -220,10 +241,14 @@ module QA
end
def click_link_with_text(text)
wait_for_requests
click_link text
end
def click_body
wait_for_requests
find('body').click
end
......
......@@ -66,10 +66,16 @@ module QA
def visit!
Runtime::Logger.debug(%Q[Visiting #{self.class.name} at "#{web_url}"])
# Just in case an async action is not yet complete
Support::WaitForRequests.wait_for_requests
Support::Retrier.retry_until do
visit(web_url)
wait { current_url.include?(URI.parse(web_url).path.split('/').last || web_url) }
end
# Wait until the new page is ready for us to interact with it
Support::WaitForRequests.wait_for_requests
end
def populate(*attributes)
......
# frozen_string_literal: true
module QA
module Support
module WaitForRequests
module_function
def wait_for_requests
Waiter.wait do
finished_all_ajax_requests? && finished_all_axios_requests?
end
end
def finished_all_axios_requests?
Capybara.page.evaluate_script('window.pendingRequests || 0').zero?
end
def finished_all_ajax_requests?
return true if Capybara.page.evaluate_script('typeof jQuery === "undefined"')
Capybara.page.evaluate_script('jQuery.active').zero?
end
end
end
end
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