diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-02 16:03:23 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-02 16:03:23 +0300 |
commit | a72a9af092c1bfcf9f8024d59c11cf222f07e1e7 (patch) | |
tree | 44b60265c1d476d026b2862d2c1244748f558d4f /qa | |
parent | b085478c4c2bed74fdc6eb2c33bfc62e791baf03 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa.rb | 1 | ||||
-rw-r--r-- | qa/qa/page/base.rb | 27 | ||||
-rw-r--r-- | qa/qa/resource/base.rb | 6 | ||||
-rw-r--r-- | qa/qa/support/wait_for_requests.rb | 25 |
4 files changed, 58 insertions, 1 deletions
@@ -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 diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index dcba4fc8544..2c04fb53440 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -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 diff --git a/qa/qa/resource/base.rb b/qa/qa/resource/base.rb index 3bb62703290..1a6c2e70860 100644 --- a/qa/qa/resource/base.rb +++ b/qa/qa/resource/base.rb @@ -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) diff --git a/qa/qa/support/wait_for_requests.rb b/qa/qa/support/wait_for_requests.rb new file mode 100644 index 00000000000..c573fc1f8e1 --- /dev/null +++ b/qa/qa/support/wait_for_requests.rb @@ -0,0 +1,25 @@ +# 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 |