From 034e7d969a591605267c0e5ddbe6f2228bf8e43d Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 15 Sep 2021 06:10:57 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- qa/qa/page/main/menu.rb | 11 +++++++++++ qa/qa/runtime/browser.rb | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'qa') diff --git a/qa/qa/page/main/menu.rb b/qa/qa/page/main/menu.rb index 760741a9630..ad5cd971afc 100644 --- a/qa/qa/page/main/menu.rb +++ b/qa/qa/page/main/menu.rb @@ -11,6 +11,7 @@ module QA view 'app/views/layouts/header/_default.html.haml' do element :navbar, required: true + element :canary_badge_link element :user_avatar, required: true element :user_menu, required: true element :stop_impersonation_link @@ -168,6 +169,16 @@ module QA click_element(:stop_impersonation_link) end + # To verify whether the user has been directed to a canary web node + # @return [Boolean] result of checking existence of :canary_badge_link element + # @example: + # Menu.perform do |menu| + # expect(menu.canary?).to be(true) + # end + def canary? + has_element?(:canary_badge_link) + end + private def within_top_menu(&block) diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb index 370c05edb86..f208a93d302 100644 --- a/qa/qa/runtime/browser.rb +++ b/qa/qa/runtime/browser.rb @@ -219,6 +219,26 @@ module QA yield.tap { clear! } if block_given? end + # To redirect the browser to a canary or non-canary web node + # after loading a subject test page + # @param [Boolean] Send to canary true or false + # @example: + # Runtime::Browser::Session.target_canary(true) + def self.target_canary(enable_canary) + if QA::Runtime::Env.qa_cookies.to_s.include?("gitlab_canary=true") + QA::Runtime::Logger.warn("WARNING: Setting cookie through QA_COOKIES var is incompatible with this method.") + return + end + + browser = Capybara.current_session.driver.browser + + if enable_canary + browser.manage.add_cookie name: "gitlab_canary", value: "true" + else + browser.manage.delete_cookie("gitlab_canary") + end + end + ## # Selenium allows to reset session cookies for current domain only. # -- cgit v1.2.3