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 ...@@ -490,6 +490,7 @@ module QA
autoload :Dates, 'qa/support/dates' autoload :Dates, 'qa/support/dates'
autoload :Waiter, 'qa/support/waiter' autoload :Waiter, 'qa/support/waiter'
autoload :Retrier, 'qa/support/retrier' autoload :Retrier, 'qa/support/retrier'
autoload :WaitForRequests, 'qa/support/wait_for_requests'
end end
end end
......
...@@ -49,13 +49,11 @@ module QA ...@@ -49,13 +49,11 @@ module QA
def approve_license(name) def approve_license(name)
click_license(name) click_license(name)
click_element(:approve_license_button) click_element(:approve_license_button)
wait_for_animated_element(:license_management_modal)
end end
def blacklist_license(name) def blacklist_license(name)
click_license(name) click_license(name)
click_element(:blacklist_license_button) click_element(:blacklist_license_button)
wait_for_animated_element(:license_management_modal)
end end
end end
end end
......
...@@ -8,6 +8,7 @@ module QA ...@@ -8,6 +8,7 @@ module QA
prepend Support::Page::Logging if Runtime::Env.debug? prepend Support::Page::Logging if Runtime::Env.debug?
include Capybara::DSL include Capybara::DSL
include Scenario::Actable include Scenario::Actable
include Support::WaitForRequests
extend Validatable extend Validatable
extend SingleForwardable extend SingleForwardable
...@@ -21,6 +22,8 @@ module QA ...@@ -21,6 +22,8 @@ module QA
def refresh def refresh
page.refresh page.refresh
wait_for_requests
end end
def wait(max: 60, interval: 0.1, reload: true) def wait(max: 60, interval: 0.1, reload: true)
...@@ -42,6 +45,8 @@ module QA ...@@ -42,6 +45,8 @@ module QA
end end
def scroll_to(selector, text: nil) def scroll_to(selector, text: nil)
wait_for_requests
page.execute_script <<~JS page.execute_script <<~JS
var elements = Array.from(document.querySelectorAll('#{selector}')); var elements = Array.from(document.querySelectorAll('#{selector}'));
var text = '#{text}'; var text = '#{text}';
...@@ -74,6 +79,8 @@ module QA ...@@ -74,6 +79,8 @@ module QA
end end
def find_element(name, **kwargs) def find_element(name, **kwargs)
wait_for_requests
find(element_selector_css(name), kwargs) find(element_selector_css(name), kwargs)
end end
...@@ -82,6 +89,8 @@ module QA ...@@ -82,6 +89,8 @@ module QA
end end
def all_elements(name, **kwargs) def all_elements(name, **kwargs)
wait_for_requests
all(element_selector_css(name), **kwargs) all(element_selector_css(name), **kwargs)
end end
...@@ -120,6 +129,8 @@ module QA ...@@ -120,6 +129,8 @@ module QA
end end
def has_element?(name, **kwargs) def has_element?(name, **kwargs)
wait_for_requests
wait = kwargs[:wait] ? kwargs[:wait] && kwargs.delete(:wait) : Capybara.default_max_wait_time wait = kwargs[:wait] ? kwargs[:wait] && kwargs.delete(:wait) : Capybara.default_max_wait_time
text = kwargs[:text] ? kwargs[:text] && kwargs.delete(:text) : nil text = kwargs[:text] ? kwargs[:text] && kwargs.delete(:text) : nil
...@@ -127,6 +138,8 @@ module QA ...@@ -127,6 +138,8 @@ module QA
end end
def has_no_element?(name, **kwargs) def has_no_element?(name, **kwargs)
wait_for_requests
wait = kwargs[:wait] ? kwargs[:wait] && kwargs.delete(:wait) : Capybara.default_max_wait_time wait = kwargs[:wait] ? kwargs[:wait] && kwargs.delete(:wait) : Capybara.default_max_wait_time
text = kwargs[:text] ? kwargs[:text] && kwargs.delete(:text) : nil text = kwargs[:text] ? kwargs[:text] && kwargs.delete(:text) : nil
...@@ -134,18 +147,24 @@ module QA ...@@ -134,18 +147,24 @@ module QA
end end
def has_text?(text, wait: Capybara.default_max_wait_time) def has_text?(text, wait: Capybara.default_max_wait_time)
wait_for_requests
page.has_text?(text, wait: wait) page.has_text?(text, wait: wait)
end end
def has_no_text?(text) def has_no_text?(text)
wait_for_requests
page.has_no_text? text page.has_no_text? text
end end
def has_normalized_ws_text?(text, wait: Capybara.default_max_wait_time) 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 end
def finished_loading? def finished_loading?
wait_for_requests
# The number of selectors should be able to be reduced after # The number of selectors should be able to be reduced after
# migration to the new spinner is complete. # migration to the new spinner is complete.
# https://gitlab.com/groups/gitlab-org/-/epics/956 # https://gitlab.com/groups/gitlab-org/-/epics/956
...@@ -153,6 +172,8 @@ module QA ...@@ -153,6 +172,8 @@ module QA
end end
def finished_loading_block? def finished_loading_block?
wait_for_requests
has_no_css?('.fa-spinner.block-loading', wait: Capybara.default_max_wait_time) has_no_css?('.fa-spinner.block-loading', wait: Capybara.default_max_wait_time)
end end
...@@ -220,10 +241,14 @@ module QA ...@@ -220,10 +241,14 @@ module QA
end end
def click_link_with_text(text) def click_link_with_text(text)
wait_for_requests
click_link text click_link text
end end
def click_body def click_body
wait_for_requests
find('body').click find('body').click
end end
......
...@@ -66,10 +66,16 @@ module QA ...@@ -66,10 +66,16 @@ module QA
def visit! def visit!
Runtime::Logger.debug(%Q[Visiting #{self.class.name} at "#{web_url}"]) 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 Support::Retrier.retry_until do
visit(web_url) visit(web_url)
wait { current_url.include?(URI.parse(web_url).path.split('/').last || web_url) } wait { current_url.include?(URI.parse(web_url).path.split('/').last || web_url) }
end end
# Wait until the new page is ready for us to interact with it
Support::WaitForRequests.wait_for_requests
end end
def populate(*attributes) 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