Remove functionality of passing a block to `Runtime::Browser#visit`
The following discussion from !25704 (merged) should be addressed:
-
@rymai started a discussion: (+2 comments) In the case
&block
isn'tnil
here, this assertion will happen after the block is executed sinceBrowser#visit
callsBrowser::Session#perform
and we're callingyield
from there. For instance with:it 'user logs into Mattermost using GitLab OAuth' do Runtime::Browser.visit(:gitlab, Page::Main::Login) do Page::Main::Login.act { sign_in_using_credentials } Runtime::Browser.visit(:mattermost, Page::Mattermost::Login) do Page::Mattermost::Login.act { sign_in_using_oauth } Page::Mattermost::Main.perform do |page| expect(page).to have_content(/(Welcome to: Mattermost|Logout GitLab Mattermost)/) end end end end
What would actually happen is:
it 'user logs into Mattermost using GitLab OAuth' do Runtime::Browser.visit(:gitlab, Page::Main::Login) do Page::Main::Login.act { sign_in_using_credentials } Runtime::Browser.visit(:mattermost, Page::Mattermost::Login) do Page::Mattermost::Login.act { sign_in_using_oauth } Page::Mattermost::Main.perform do |page| expect(page).to have_content(/(Welcome to: Mattermost|Logout GitLab Mattermost)/) end end Page::Main::Login.validate_elements_present! end end
Which won't work because at the time
Page::Main::Login.validate_elements_present!
would be called, we're not on the login page anymore.To fix that, we need to move this assertion before we call the block, i.e.
diff --git a/qa/qa/runtime/address.rb b/qa/qa/runtime/address.rb index 98d042fb43a..1d1c1c850b9 100644 --- a/qa/qa/runtime/address.rb +++ b/qa/qa/runtime/address.rb @@ -5,9 +5,9 @@ module QA class Address attr_reader :address - def initialize(instance, page = nil) + def initialize(instance, page) @instance = instance - @address = host + (page.is_a?(String) ? page : page&.path) + @address = host + page.path end def host diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb index 8023bee0e6d..a19982a933f 100644 --- a/qa/qa/runtime/browser.rb +++ b/qa/qa/runtime/browser.rb @@ -27,13 +27,12 @@ module QA # In case of an address that is a symbol we will try to guess address # based on `Runtime::Scenario#something_address`. # - def visit(address, page = nil, &block) - Browser::Session.new(address, page).perform(&block) + def visit(address, page_class, &block) + Browser::Session.new(address, page_class).perform(&block) end - def self.visit(address, page = nil, &block) - new.visit(address, page, &block) - page.validate_elements_present! + def self.visit(address, page_class, &block) + new.visit(address, page_class, &block) end def self.configure! @@ -128,8 +127,11 @@ module QA class Session include Capybara::DSL - def initialize(instance, page = nil) - @session_address = Runtime::Address.new(instance, page) + attr_reader :page_class + + def initialize(instance, page_class) + @session_address = Runtime::Address.new(instance, page_class) + @page_class = page_class end def url @@ -139,6 +141,8 @@ module QA def perform(&block) visit(url) + page_class.validate_elements_present! + if QA::Runtime::Env.qa_cookies browser = Capybara.current_session.driver.browser QA::Runtime::Env.qa_cookies.each do |cookie|