diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-10 15:07:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-10 15:07:47 +0300 |
commit | 96b0c1245c93585a8b0fe23e22306d32ff4e4905 (patch) | |
tree | d2904751e1a2529e8239381ce747339cdbf5116c /qa | |
parent | 0ba3a054d2190094ffda1ebe3aa53ffc5b92247d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa/page/base.rb | 15 | ||||
-rw-r--r-- | qa/qa/page/main/menu.rb | 10 | ||||
-rw-r--r-- | qa/qa/page/search/results.rb | 15 | ||||
-rw-r--r-- | qa/qa/page/validatable.rb | 3 | ||||
-rw-r--r-- | qa/qa/resource/repository/commit.rb | 2 | ||||
-rw-r--r-- | qa/qa/runtime/search.rb | 79 | ||||
-rw-r--r-- | qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb | 2 | ||||
-rw-r--r-- | qa/qa/support/page/logging.rb | 1 |
8 files changed, 104 insertions, 23 deletions
diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index 3ac714940cd..29946791df7 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -132,20 +132,25 @@ module QA element.select value end + def has_active_element?(name, **kwargs) + has_element?(name, class: 'active', **kwargs) + 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 + wait = kwargs.delete(:wait) || Capybara.default_max_wait_time + text = kwargs.delete(:text) + klass = kwargs.delete(:class) - has_css?(element_selector_css(name, kwargs), text: text, wait: wait) + has_css?(element_selector_css(name, kwargs), text: text, wait: wait, class: klass) 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 + wait = kwargs.delete(:wait) || Capybara.default_max_wait_time + text = kwargs.delete(:text) has_no_css?(element_selector_css(name, kwargs), wait: wait, text: text) end diff --git a/qa/qa/page/main/menu.rb b/qa/qa/page/main/menu.rb index 5f4b3946e6a..8ad30632fa1 100644 --- a/qa/qa/page/main/menu.rb +++ b/qa/qa/page/main/menu.rb @@ -76,8 +76,14 @@ module QA end def sign_out - within_user_menu do - click_element :sign_out_link + retry_until do + break true unless signed_in? + + within_user_menu do + click_element :sign_out_link + end + + has_no_element?(:user_avatar) end end diff --git a/qa/qa/page/search/results.rb b/qa/qa/page/search/results.rb index 2f99d8da784..85f1d224935 100644 --- a/qa/qa/page/search/results.rb +++ b/qa/qa/page/search/results.rb @@ -19,11 +19,11 @@ module QA::Page end def switch_to_code - click_element(:code_tab) + switch_to_tab(:code_tab) end def switch_to_projects - click_element(:projects_tab) + switch_to_tab(:projects_tab) end def has_file_in_project?(file_name, project_name) @@ -32,7 +32,7 @@ module QA::Page def has_file_with_content?(file_name, file_text) within_element_by_index(:result_item_content, 0) do - false unless has_element?(:file_title_content, text: file_name) + break false unless has_element?(:file_title_content, text: file_name) has_element?(:file_text_content, text: file_text) end @@ -41,6 +41,15 @@ module QA::Page def has_project?(project_name) has_element?(:project, project_name: project_name) end + + private + + def switch_to_tab(tab) + retry_until do + click_element(tab) + has_active_element?(tab) + end + end end end end diff --git a/qa/qa/page/validatable.rb b/qa/qa/page/validatable.rb index 8467d261285..20aad65688d 100644 --- a/qa/qa/page/validatable.rb +++ b/qa/qa/page/validatable.rb @@ -11,8 +11,7 @@ module QA elements.each do |element| next unless element.required? - # TODO: this wait needs to be replaced by the wait class - unless base_page.has_element?(element.name, wait: 60) + unless base_page.wait(reload: false) { base_page.has_element?(element.name, wait: 15) } raise Validatable::PageValidationError, "#{element.name} did not appear on #{self.name} as expected" end end diff --git a/qa/qa/resource/repository/commit.rb b/qa/qa/resource/repository/commit.rb index 4b5e8535ade..e3fb5bf486d 100644 --- a/qa/qa/resource/repository/commit.rb +++ b/qa/qa/resource/repository/commit.rb @@ -11,6 +11,8 @@ module QA :file_path, :sha + attribute :short_id + attribute :project do Project.fabricate! do |resource| resource.name = 'project-with-commit' diff --git a/qa/qa/runtime/search.rb b/qa/qa/runtime/search.rb index faa110c96e7..74402301098 100644 --- a/qa/qa/runtime/search.rb +++ b/qa/qa/runtime/search.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'securerandom' + module QA module Runtime module Search @@ -8,26 +10,83 @@ module QA ElasticSearchServerError = Class.new(RuntimeError) - def elasticsearch_responding? + def assert_elasticsearch_responding QA::Runtime::Logger.debug("Attempting to search via Elasticsearch...") - QA::Support::Retrier.retry_on_exception do - # We don't care about the results of the search, we just need - # any search that uses Elasticsearch, not the native search - # The Elasticsearch-only scopes are blobs, wiki_blobs, and commits. - request = Runtime::API::Request.new(api_client, "/search?scope=blobs&search=foo") - response = get(request.url) + QA::Support::Retrier.retry_on_exception(max_attempts: 3) do + search_term = SecureRandom.hex(8) + + QA::Runtime::Logger.debug("Creating commit and project including search term '#{search_term}'...") - unless response.code == singleton_class::HTTP_STATUS_OK - raise ElasticSearchServerError, "Search attempt failed. Request returned (#{response.code}): `#{response}`." + content = "Elasticsearch test commit #{search_term}" + project = Resource::Project.fabricate_via_api! do |project| + project.name = "project-to-search-#{search_term}" + end + commit = Resource::Repository::Commit.fabricate_via_api! do |commit| + commit.project = project + commit.commit_message = content + commit.add_files( + [ + { + file_path: 'test.txt', + content: content + } + ] + ) end - true + find_commit(commit, "commit*#{search_term}") + find_project(project, "to-search*#{search_term}") + end + end + + def find_code(file_name, search_term) + find_target_in_scope('blobs', search_term) do |record| + record[:filename] == file_name && record[:data].include?(search_term) end + + QA::Runtime::Logger.debug("Found file '#{file_name} containing code '#{search_term}'") + end + + def find_commit(commit, search_term) + find_target_in_scope('commits', search_term) do |record| + record[:message] == commit.commit_message + end + + QA::Runtime::Logger.debug("Found commit '#{commit.commit_message} (#{commit.short_id})' via '#{search_term}'") + end + + def find_project(project, search_term) + find_target_in_scope('projects', search_term) do |record| + record[:name] == project.name + end + + QA::Runtime::Logger.debug("Found project '#{project.name}' via '#{search_term}'") end private + def find_target_in_scope(scope, search_term) + QA::Support::Retrier.retry_until(max_attempts: 10, sleep_interval: 10, raise_on_failure: true, retry_on_exception: true) do + result = search(scope, search_term) + result && result.any? { |record| yield record } + end + end + + def search(scope, term) + QA::Runtime::Logger.debug("Search scope '#{scope}' for '#{term}'...") + request = Runtime::API::Request.new(api_client, "/search?scope=#{scope}&search=#{term}") + response = get(request.url) + + unless response.code == singleton_class::HTTP_STATUS_OK + msg = "Search attempt failed. Request returned (#{response.code}): `#{response}`." + QA::Runtime::Logger.debug(msg) + raise ElasticSearchServerError, msg + end + + parse_body(response) + end + def api_client @api_client ||= Runtime::API::Client.new(:gitlab) end diff --git a/qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb b/qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb index 74e2f51cf28..d78ad6d86d3 100644 --- a/qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb +++ b/qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb @@ -2,7 +2,7 @@ module QA context 'Performance bar' do - context 'when logged in as an admin user', :requires_admin do + context 'when logged in as an admin user', :requires_admin, quarantine: 'https://gitlab.com/gitlab-org/gitlab/issues/196141' do before do Flow::Login.sign_in_as_admin Page::Main::Menu.perform(&:go_to_admin_area) diff --git a/qa/qa/support/page/logging.rb b/qa/qa/support/page/logging.rb index 5d73d9635f8..8420f4112e9 100644 --- a/qa/qa/support/page/logging.rb +++ b/qa/qa/support/page/logging.rb @@ -173,6 +173,7 @@ module QA def log_has_element_or_not(method, name, found, **kwargs) msg = ["#{method} :#{name}"] 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})" msg << "returned: #{found}" |