From 0430524bfea1700da34b78d7d323c69bb7f715e6 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 17 Nov 2017 14:48:52 +0100 Subject: WIP Handle domain sessions better in QA test scenario [ci skip] --- qa/qa.rb | 1 + qa/qa/page/base.rb | 14 ++++++ qa/qa/page/main/entry.rb | 16 +----- qa/qa/runtime/browser.rb | 70 +++++++++++++++++++++++++++ qa/qa/scenario/entrypoint.rb | 1 - qa/qa/specs/config.rb | 63 ------------------------ qa/qa/specs/features/login/standard_spec.rb | 2 +- qa/qa/specs/features/mattermost/login_spec.rb | 14 ++++-- qa/qa/specs/runner.rb | 2 +- 9 files changed, 98 insertions(+), 85 deletions(-) create mode 100644 qa/qa/runtime/browser.rb delete mode 100644 qa/qa/specs/config.rb diff --git a/qa/qa.rb b/qa/qa.rb index dc1cd9abc6a..5bd0b478c71 100644 --- a/qa/qa.rb +++ b/qa/qa.rb @@ -9,6 +9,7 @@ module QA autoload :User, 'qa/runtime/user' autoload :Namespace, 'qa/runtime/namespace' autoload :Scenario, 'qa/runtime/scenario' + autoload :Browser, 'qa/runtime/browser' end ## diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index bdddfb877c5..8c4d3ede3d7 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -7,6 +7,20 @@ module QA def refresh visit current_url end + + def wait(css = '.application', time: 60) + # This resolves cold boot / background tasks problems + # + Time.now.tap do |start| + while Time.now - start < time + break if page.has_css?(css, wait: 5) + puts "Waiting for `#{css} on `#{current_url}`" + refresh + end + end + + yield if block_given? + end end end end diff --git a/qa/qa/page/main/entry.rb b/qa/qa/page/main/entry.rb index ac939732b1d..78467f8dcd5 100644 --- a/qa/qa/page/main/entry.rb +++ b/qa/qa/page/main/entry.rb @@ -3,20 +3,8 @@ module QA module Main class Entry < Page::Base def visit_login_page - visit("#{Runtime::Scenario.gitlab_address}/users/sign_in") - wait_for_instance_to_be_ready - end - - private - - def wait_for_instance_to_be_ready - # This resolves cold boot / background tasks problems - # - start = Time.now - - while Time.now - start < 240 - break if page.has_css?('.application', wait: 10) - refresh + wait(time: 500) do + visit("#{Runtime::Scenario.gitlab_address}/users/sign_in") end end end diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb new file mode 100644 index 00000000000..b27f5676108 --- /dev/null +++ b/qa/qa/runtime/browser.rb @@ -0,0 +1,70 @@ +require 'rspec/core' +require 'capybara/rspec' +require 'capybara-screenshot/rspec' +require 'selenium-webdriver' + +module QA + module Runtime + module Browser + extend self + + def session(address, &block) + configure! + page.visit(address) + + block.call(page) + + page.visit(address) + reset_domain_session! + rescue + # RSpec examples will take care of screenshots on their own + # + unless block.binding.receiver.class < RSpec::Core::ExampleGroup + Capybara::Screenshot.screenshot_and_save_page + end + + raise + end + + def page + Capybara.current_session + end + + def reset_domain_session(address) + ## + # Selenium allows to reset session cookies for current domain only. + # + # See gitlab-org/gitlab-qa#102 + # + Capybar.reset_session! + end + + def configure! + return if Capybara.drivers.include?(:chrome) + + Capybara.register_driver :chrome do |app| + capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( + 'chromeOptions' => { + 'args' => %w[headless no-sandbox disable-gpu window-size=1280,1680] + } + ) + + Capybara::Selenium::Driver + .new(app, browser: :chrome, desired_capabilities: capabilities) + end + + Capybara::Screenshot.register_driver(:chrome) do |driver, path| + driver.browser.save_screenshot(path) + end + + Capybara.configure do |config| + config.default_driver = :chrome + config.javascript_driver = :chrome + config.default_max_wait_time = 4 + # https://github.com/mattheworiordan/capybara-screenshot/issues/164 + config.save_path = 'tmp' + end + end + end + end +end diff --git a/qa/qa/scenario/entrypoint.rb b/qa/qa/scenario/entrypoint.rb index b9d924651a0..ae099fd911e 100644 --- a/qa/qa/scenario/entrypoint.rb +++ b/qa/qa/scenario/entrypoint.rb @@ -8,7 +8,6 @@ module QA include Bootable def perform(address, *files) - Specs::Config.act { configure_capybara! } Runtime::Scenario.define(:gitlab_address, address) ## diff --git a/qa/qa/specs/config.rb b/qa/qa/specs/config.rb deleted file mode 100644 index bce7923e52d..00000000000 --- a/qa/qa/specs/config.rb +++ /dev/null @@ -1,63 +0,0 @@ -require 'rspec/core' -require 'capybara/rspec' -require 'capybara-screenshot/rspec' -require 'selenium-webdriver' - -# rubocop:disable Metrics/MethodLength -# rubocop:disable Metrics/LineLength - -module QA - module Specs - class Config < Scenario::Template - include Scenario::Actable - - def perform - configure_rspec! - configure_capybara! - end - - def configure_rspec! - RSpec.configure do |config| - config.expect_with :rspec do |expectations| - expectations.include_chain_clauses_in_custom_matcher_descriptions = true - end - - config.mock_with :rspec do |mocks| - mocks.verify_partial_doubles = true - end - - config.order = :random - Kernel.srand config.seed - config.formatter = :documentation - config.color = true - end - end - - def configure_capybara! - Capybara.register_driver :chrome do |app| - capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( - 'chromeOptions' => { - 'args' => %w[headless no-sandbox disable-gpu window-size=1280,1680] - } - ) - - Capybara::Selenium::Driver - .new(app, browser: :chrome, desired_capabilities: capabilities) - end - - Capybara::Screenshot.register_driver(:chrome) do |driver, path| - driver.browser.save_screenshot(path) - end - - Capybara.configure do |config| - config.default_driver = :chrome - config.javascript_driver = :chrome - config.default_max_wait_time = 10 - - # https://github.com/mattheworiordan/capybara-screenshot/issues/164 - config.save_path = 'tmp' - end - end - end - end -end diff --git a/qa/qa/specs/features/login/standard_spec.rb b/qa/qa/specs/features/login/standard_spec.rb index b155708c387..a8471158ef1 100644 --- a/qa/qa/specs/features/login/standard_spec.rb +++ b/qa/qa/specs/features/login/standard_spec.rb @@ -1,5 +1,5 @@ module QA - feature 'standard root login', :core do + feature 'standard user login', :core do scenario 'user logs in using credentials' do Page::Main::Entry.act { visit_login_page } Page::Main::Login.act { sign_in_using_credentials } diff --git a/qa/qa/specs/features/mattermost/login_spec.rb b/qa/qa/specs/features/mattermost/login_spec.rb index 92f91cb2725..ea4e1b16678 100644 --- a/qa/qa/specs/features/mattermost/login_spec.rb +++ b/qa/qa/specs/features/mattermost/login_spec.rb @@ -1,12 +1,16 @@ module QA feature 'logging in to Mattermost', :mattermost do scenario 'can use gitlab oauth' do - Page::Main::Entry.act { visit_login_page } - Page::Main::Login.act { sign_in_using_credentials } - Page::Mattermost::Login.act { sign_in_using_oauth } + Runtime::Browser.session(Page::Gitlab::Login) do + Page::Main::Login.act { sign_in_using_credentials } - Page::Mattermost::Main.perform do |page| - expect(page).to have_content(/(Welcome to: Mattermost|Logout GitLab Mattermost)/) + Runtime::Browser.session(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 end diff --git a/qa/qa/specs/runner.rb b/qa/qa/specs/runner.rb index f98b8f88e9a..3f7b75df986 100644 --- a/qa/qa/specs/runner.rb +++ b/qa/qa/specs/runner.rb @@ -17,7 +17,7 @@ module QA tags.to_a.each { |tag| args.push(['-t', tag.to_s]) } args.push(files) - Specs::Config.perform + Runtime::Browser.configure! RSpec::Core::Runner.run(args.flatten, $stderr, $stdout).tap do |status| abort if status.nonzero? -- cgit v1.2.1 From a618b122f9b3bd0a71a90b03629a90ca2f6b29cc Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 17 Nov 2017 17:40:32 +0100 Subject: Use QA browser to navigate to pages and handle sessions [ci skip] --- qa/qa/page/base.rb | 19 +++++++++++++++++++ qa/qa/page/main/entry.rb | 6 +----- qa/qa/page/main/login.rb | 8 ++++++++ qa/qa/page/mattermost/login.rb | 4 ++-- qa/qa/runtime/browser.rb | 16 ++++++++++++---- qa/qa/specs/features/login/standard_spec.rb | 2 +- qa/qa/specs/features/mattermost/group_create_spec.rb | 2 +- qa/qa/specs/features/mattermost/login_spec.rb | 4 ++-- qa/qa/specs/features/project/create_spec.rb | 2 +- qa/qa/specs/features/repository/clone_spec.rb | 2 +- qa/qa/specs/features/repository/push_spec.rb | 2 +- 11 files changed, 49 insertions(+), 18 deletions(-) diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index 8c4d3ede3d7..a43192ed903 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -21,6 +21,25 @@ module QA yield if block_given? end + + ## + # If you want to use specific page class as an entrypoint + # for Runtime::Browser.session, you need to implement this + # method in a subclass. + # + def self.address + raise NotImplementedError + end + + ## TODO + # When we navigate through pages, we want to check if we are on a + # valid page everytime we instantiate a new Page object. + # + # See gitlab-org/gitlab-qa#111 + # + # def self.pattern + # raise NotImplementedError + # end end end end diff --git a/qa/qa/page/main/entry.rb b/qa/qa/page/main/entry.rb index 78467f8dcd5..c6e1706a66d 100644 --- a/qa/qa/page/main/entry.rb +++ b/qa/qa/page/main/entry.rb @@ -2,11 +2,7 @@ module QA module Page module Main class Entry < Page::Base - def visit_login_page - wait(time: 500) do - visit("#{Runtime::Scenario.gitlab_address}/users/sign_in") - end - end + # TODO remove this class end end end diff --git a/qa/qa/page/main/login.rb b/qa/qa/page/main/login.rb index 8b0111a78a2..37580ad89b1 100644 --- a/qa/qa/page/main/login.rb +++ b/qa/qa/page/main/login.rb @@ -2,6 +2,14 @@ module QA module Page module Main class Login < Page::Base + def self.address + Runtime::Scenario.gitlab_address + '/users/sign_in' + end + + def initialize + wait('.application', time: 500) + end + def sign_in_using_credentials if page.has_content?('Change your password') fill_in :user_password, with: Runtime::User.password diff --git a/qa/qa/page/mattermost/login.rb b/qa/qa/page/mattermost/login.rb index 42ab9c6f675..846a96d20bf 100644 --- a/qa/qa/page/mattermost/login.rb +++ b/qa/qa/page/mattermost/login.rb @@ -2,8 +2,8 @@ module QA module Page module Mattermost class Login < Page::Base - def initialize - visit(Runtime::Scenario.mattermost_address + '/login') + def self.address + Runtime::Scenario.mattermost_address + '/login' end def sign_in_using_oauth diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb index b27f5676108..a14a4adce22 100644 --- a/qa/qa/runtime/browser.rb +++ b/qa/qa/runtime/browser.rb @@ -8,14 +8,18 @@ module QA module Browser extend self - def session(address, &block) + def visit(entry, &block) + address = entry.is_a?(String) ? entry : entry.address + configure! page.visit(address) - block.call(page) + if block_given? + block.call(page) - page.visit(address) - reset_domain_session! + page.visit(address) + reset_domain_session! + end rescue # RSpec examples will take care of screenshots on their own # @@ -26,6 +30,10 @@ module QA raise end + ## + # Current session, when Capybara::DSL is included `page` method is + # mixed in as well. + # def page Capybara.current_session end diff --git a/qa/qa/specs/features/login/standard_spec.rb b/qa/qa/specs/features/login/standard_spec.rb index a8471158ef1..7a501d3f873 100644 --- a/qa/qa/specs/features/login/standard_spec.rb +++ b/qa/qa/specs/features/login/standard_spec.rb @@ -1,7 +1,7 @@ module QA feature 'standard user login', :core do scenario 'user logs in using credentials' do - Page::Main::Entry.act { visit_login_page } + Runtime::Browser.visit(Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } # TODO, since `Signed in successfully` message was removed diff --git a/qa/qa/specs/features/mattermost/group_create_spec.rb b/qa/qa/specs/features/mattermost/group_create_spec.rb index 853a9a6a4f4..5156481c8e5 100644 --- a/qa/qa/specs/features/mattermost/group_create_spec.rb +++ b/qa/qa/specs/features/mattermost/group_create_spec.rb @@ -1,7 +1,7 @@ module QA feature 'create a new group', :mattermost do scenario 'creating a group with a mattermost team' do - Page::Main::Entry.act { visit_login_page } + Runtime::Browser.visit(Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } Page::Main::Menu.act { go_to_groups } diff --git a/qa/qa/specs/features/mattermost/login_spec.rb b/qa/qa/specs/features/mattermost/login_spec.rb index ea4e1b16678..449161e2bb7 100644 --- a/qa/qa/specs/features/mattermost/login_spec.rb +++ b/qa/qa/specs/features/mattermost/login_spec.rb @@ -1,10 +1,10 @@ module QA feature 'logging in to Mattermost', :mattermost do scenario 'can use gitlab oauth' do - Runtime::Browser.session(Page::Gitlab::Login) do + Runtime::Browser.visit(Page::Gitlab::Login) do Page::Main::Login.act { sign_in_using_credentials } - Runtime::Browser.session(Page::Mattermost::Login) do + Runtime::Browser.visit(Page::Mattermost::Login) do Page::Mattermost::Login.act { sign_in_using_oauth } Page::Mattermost::Main.perform do |page| diff --git a/qa/qa/specs/features/project/create_spec.rb b/qa/qa/specs/features/project/create_spec.rb index aba0c2b4c14..46c805d8b25 100644 --- a/qa/qa/specs/features/project/create_spec.rb +++ b/qa/qa/specs/features/project/create_spec.rb @@ -1,7 +1,7 @@ module QA feature 'create a new project', :core do scenario 'user creates a new project' do - Page::Main::Entry.act { visit_login_page } + Runtime::Browser.visit(Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } Scenario::Gitlab::Project::Create.perform do |project| diff --git a/qa/qa/specs/features/repository/clone_spec.rb b/qa/qa/specs/features/repository/clone_spec.rb index 5cc3b3b9c1b..18972c918a6 100644 --- a/qa/qa/specs/features/repository/clone_spec.rb +++ b/qa/qa/specs/features/repository/clone_spec.rb @@ -9,7 +9,7 @@ module QA end before do - Page::Main::Entry.act { visit_login_page } + Runtime::Browser.visit(Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } Scenario::Gitlab::Project::Create.perform do |scenario| diff --git a/qa/qa/specs/features/repository/push_spec.rb b/qa/qa/specs/features/repository/push_spec.rb index 30935dc1e13..9ef532fd4a5 100644 --- a/qa/qa/specs/features/repository/push_spec.rb +++ b/qa/qa/specs/features/repository/push_spec.rb @@ -2,7 +2,7 @@ module QA feature 'push code to repository', :core do context 'with regular account over http' do scenario 'user pushes code to the repository' do - Page::Main::Entry.act { visit_login_page } + Runtime::Browser.visit(Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } Scenario::Gitlab::Project::Create.perform do |scenario| -- cgit v1.2.1 From 6e1df95ed3a552e4c4dc61150dc2825508d888ec Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 17 Nov 2017 17:51:09 +0100 Subject: Remove GitLab entry page class in QA [ci skip] --- qa/qa.rb | 1 - qa/qa/page/main/entry.rb | 9 --------- 2 files changed, 10 deletions(-) delete mode 100644 qa/qa/page/main/entry.rb diff --git a/qa/qa.rb b/qa/qa.rb index 5bd0b478c71..3089e515082 100644 --- a/qa/qa.rb +++ b/qa/qa.rb @@ -62,7 +62,6 @@ module QA autoload :Base, 'qa/page/base' module Main - autoload :Entry, 'qa/page/main/entry' autoload :Login, 'qa/page/main/login' autoload :Menu, 'qa/page/main/menu' end diff --git a/qa/qa/page/main/entry.rb b/qa/qa/page/main/entry.rb deleted file mode 100644 index c6e1706a66d..00000000000 --- a/qa/qa/page/main/entry.rb +++ /dev/null @@ -1,9 +0,0 @@ -module QA - module Page - module Main - class Entry < Page::Base - # TODO remove this class - end - end - end -end -- cgit v1.2.1 From 4c37cf684d75297a88db2dd1c286a68fd8aec701 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 19 Nov 2017 12:36:16 +0100 Subject: Make QA runtime browser an actable object [ci skip] --- qa/qa/page/base.rb | 15 ----- qa/qa/page/main/login.rb | 8 +-- qa/qa/page/mattermost/login.rb | 8 +-- qa/qa/runtime/browser.rb | 83 +++++++++++++++------------ qa/qa/specs/features/mattermost/login_spec.rb | 2 +- 5 files changed, 56 insertions(+), 60 deletions(-) diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index a43192ed903..69f14386223 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -22,24 +22,9 @@ module QA yield if block_given? end - ## - # If you want to use specific page class as an entrypoint - # for Runtime::Browser.session, you need to implement this - # method in a subclass. - # def self.address raise NotImplementedError end - - ## TODO - # When we navigate through pages, we want to check if we are on a - # valid page everytime we instantiate a new Page object. - # - # See gitlab-org/gitlab-qa#111 - # - # def self.pattern - # raise NotImplementedError - # end end end end diff --git a/qa/qa/page/main/login.rb b/qa/qa/page/main/login.rb index 37580ad89b1..4c38f81bce7 100644 --- a/qa/qa/page/main/login.rb +++ b/qa/qa/page/main/login.rb @@ -2,10 +2,6 @@ module QA module Page module Main class Login < Page::Base - def self.address - Runtime::Scenario.gitlab_address + '/users/sign_in' - end - def initialize wait('.application', time: 500) end @@ -21,6 +17,10 @@ module QA fill_in :user_password, with: Runtime::User.password click_button 'Sign in' end + + def self.address + Runtime::Scenario.gitlab_address + '/users/sign_in' + end end end end diff --git a/qa/qa/page/mattermost/login.rb b/qa/qa/page/mattermost/login.rb index 846a96d20bf..9eb43fdc1b2 100644 --- a/qa/qa/page/mattermost/login.rb +++ b/qa/qa/page/mattermost/login.rb @@ -2,10 +2,6 @@ module QA module Page module Mattermost class Login < Page::Base - def self.address - Runtime::Scenario.mattermost_address + '/login' - end - def sign_in_using_oauth click_link class: 'btn btn-custom-login gitlab' @@ -13,6 +9,10 @@ module QA click_button 'Authorize' end end + + def self.address + Runtime::Scenario.gitlab_address + '/login' + end end end end diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb index a14a4adce22..2226c56c012 100644 --- a/qa/qa/runtime/browser.rb +++ b/qa/qa/runtime/browser.rb @@ -5,49 +5,24 @@ require 'selenium-webdriver' module QA module Runtime - module Browser - extend self + class Browser + include Scenario::Actable - def visit(entry, &block) - address = entry.is_a?(String) ? entry : entry.address - - configure! - page.visit(address) - - if block_given? - block.call(page) + def initialize + self.class.configure! + end - page.visit(address) - reset_domain_session! - end - rescue - # RSpec examples will take care of screenshots on their own - # - unless block.binding.receiver.class < RSpec::Core::ExampleGroup - Capybara::Screenshot.screenshot_and_save_page + def visit(page, &block) + Browser::Session.new(page).tap do |session| + session.perform(&block) end - - raise end - ## - # Current session, when Capybara::DSL is included `page` method is - # mixed in as well. - # - def page - Capybara.current_session + def self.visit(page, &block) + new.visit(page, &block) end - def reset_domain_session(address) - ## - # Selenium allows to reset session cookies for current domain only. - # - # See gitlab-org/gitlab-qa#102 - # - Capybar.reset_session! - end - - def configure! + def self.configure! return if Capybara.drivers.include?(:chrome) Capybara.register_driver :chrome do |app| @@ -73,6 +48,42 @@ module QA config.save_path = 'tmp' end end + + class Session + include Capybara::DSL + + attr_reader :address + + def initialize(page) + @address = page.is_a?(String) ? page : page.address + end + + def perform(&block) + visit(@address) + + block.call if block_given? + rescue + # RSpec examples will take care of screenshots on their own + # + unless block.binding.receiver.class < RSpec::Core::ExampleGroup + Capybara::Screenshot.screenshot_and_save_page + end + + raise + ensure + clear! if block_given? + end + + ## + # Selenium allows to reset session cookies for current domain only. + # + # See gitlab-org/gitlab-qa#102 + # + def clear! + visit(@address) + Capybara.reset_session! + end + end end end end diff --git a/qa/qa/specs/features/mattermost/login_spec.rb b/qa/qa/specs/features/mattermost/login_spec.rb index 449161e2bb7..7820170a345 100644 --- a/qa/qa/specs/features/mattermost/login_spec.rb +++ b/qa/qa/specs/features/mattermost/login_spec.rb @@ -1,7 +1,7 @@ module QA feature 'logging in to Mattermost', :mattermost do scenario 'can use gitlab oauth' do - Runtime::Browser.visit(Page::Gitlab::Login) do + Runtime::Browser.visit(Page::Main::Login) do Page::Main::Login.act { sign_in_using_credentials } Runtime::Browser.visit(Page::Mattermost::Login) do -- cgit v1.2.1 From 043810f7f4cdf050ff6a32a743a352fa68754274 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 7 Dec 2017 14:01:30 +0100 Subject: Fix runtime QA browser and capturing screenshots [ci skip] --- qa/qa/runtime/browser.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb index 2226c56c012..16fa3a1bd23 100644 --- a/qa/qa/runtime/browser.rb +++ b/qa/qa/runtime/browser.rb @@ -6,7 +6,7 @@ require 'selenium-webdriver' module QA module Runtime class Browser - include Scenario::Actable + include QA::Scenario::Actable def initialize self.class.configure! @@ -63,9 +63,11 @@ module QA block.call if block_given? rescue + raise if block.nil? + # RSpec examples will take care of screenshots on their own # - unless block.binding.receiver.class < RSpec::Core::ExampleGroup + unless block.binding.receiver.is_a?(RSpec::Core::ExampleGroup) Capybara::Screenshot.screenshot_and_save_page end -- cgit v1.2.1 From 86aa7ac13bc256b6e35d6e02773598ca01a552b9 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 7 Dec 2017 14:31:39 +0100 Subject: Fix QA group creation by filling required fileds --- qa/qa/page/group/new.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/qa/qa/page/group/new.rb b/qa/qa/page/group/new.rb index cb743a7bf11..53fdaaed078 100644 --- a/qa/qa/page/group/new.rb +++ b/qa/qa/page/group/new.rb @@ -4,6 +4,7 @@ module QA class New < Page::Base def set_path(path) fill_in 'group_path', with: path + fill_in 'group_name', with: path end def set_description(description) -- cgit v1.2.1 From b80dc88441ff251096d23e596f8933cab072912f Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 7 Dec 2017 14:55:51 +0100 Subject: Decouple subject's address from page objects in QA --- qa/qa/page/base.rb | 8 +++--- qa/qa/page/main/login.rb | 4 +-- qa/qa/page/mattermost/login.rb | 4 +-- qa/qa/runtime/browser.rb | 32 +++++++++++++++++----- qa/qa/specs/features/login/standard_spec.rb | 2 +- .../specs/features/mattermost/group_create_spec.rb | 2 +- qa/qa/specs/features/mattermost/login_spec.rb | 15 ++-------- qa/qa/specs/features/project/create_spec.rb | 2 +- qa/qa/specs/features/repository/clone_spec.rb | 2 +- qa/qa/specs/features/repository/push_spec.rb | 2 +- 10 files changed, 40 insertions(+), 33 deletions(-) diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index 1d4a5c54969..4e1a55337c9 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -22,10 +22,6 @@ module QA yield if block_given? end - def self.address - raise NotImplementedError - end - def scroll_to(selector, text: nil) page.execute_script <<~JS var elements = Array.from(document.querySelectorAll('#{selector}')); @@ -40,6 +36,10 @@ module QA page.within(selector) { yield } if block_given? end + + def self.path + raise NotImplementedError + end end end end diff --git a/qa/qa/page/main/login.rb b/qa/qa/page/main/login.rb index 4c38f81bce7..f88325f408b 100644 --- a/qa/qa/page/main/login.rb +++ b/qa/qa/page/main/login.rb @@ -18,8 +18,8 @@ module QA click_button 'Sign in' end - def self.address - Runtime::Scenario.gitlab_address + '/users/sign_in' + def self.path + '/users/sign_in' end end end diff --git a/qa/qa/page/mattermost/login.rb b/qa/qa/page/mattermost/login.rb index 9eb43fdc1b2..8ffd4fdad13 100644 --- a/qa/qa/page/mattermost/login.rb +++ b/qa/qa/page/mattermost/login.rb @@ -10,8 +10,8 @@ module QA end end - def self.address - Runtime::Scenario.gitlab_address + '/login' + def self.path + '/login' end end end diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb index 16fa3a1bd23..e05dd9612df 100644 --- a/qa/qa/runtime/browser.rb +++ b/qa/qa/runtime/browser.rb @@ -12,14 +12,25 @@ module QA self.class.configure! end - def visit(page, &block) - Browser::Session.new(page).tap do |session| + ## + # Visit a page that belongs to a GitLab instance under given address. + # + # Example: + # + # visit(:gitlab, Page::Main::Login) + # visit('http://gitlab.example/users/sign_in') + # + # 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, &block) + Browser::Session.new(address, page).tap do |session| session.perform(&block) end end - def self.visit(page, &block) - new.visit(page, &block) + def self.visit(address, page, &block) + new.visit(address, page, &block) end def self.configure! @@ -52,10 +63,17 @@ module QA class Session include Capybara::DSL - attr_reader :address + def initialize(instance, page = nil) + @instance = instance + @address = host + page&.path + end - def initialize(page) - @address = page.is_a?(String) ? page : page.address + def host + if @instance.is_a?(Symbol) + Runtime::Scenario.send("#{@instance}_address") + else + @instance.to_s + end end def perform(&block) diff --git a/qa/qa/specs/features/login/standard_spec.rb b/qa/qa/specs/features/login/standard_spec.rb index 7a501d3f873..9eaa2b772e6 100644 --- a/qa/qa/specs/features/login/standard_spec.rb +++ b/qa/qa/specs/features/login/standard_spec.rb @@ -1,7 +1,7 @@ module QA feature 'standard user login', :core do scenario 'user logs in using credentials' do - Runtime::Browser.visit(Page::Main::Login) + Runtime::Browser.visit(:gitlab, Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } # TODO, since `Signed in successfully` message was removed diff --git a/qa/qa/specs/features/mattermost/group_create_spec.rb b/qa/qa/specs/features/mattermost/group_create_spec.rb index 5156481c8e5..b3dbe44bf6e 100644 --- a/qa/qa/specs/features/mattermost/group_create_spec.rb +++ b/qa/qa/specs/features/mattermost/group_create_spec.rb @@ -1,7 +1,7 @@ module QA feature 'create a new group', :mattermost do scenario 'creating a group with a mattermost team' do - Runtime::Browser.visit(Page::Main::Login) + Runtime::Browser.visit(:gitlab, Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } Page::Main::Menu.act { go_to_groups } diff --git a/qa/qa/specs/features/mattermost/login_spec.rb b/qa/qa/specs/features/mattermost/login_spec.rb index 4b3987efcb3..637bbdd643a 100644 --- a/qa/qa/specs/features/mattermost/login_spec.rb +++ b/qa/qa/specs/features/mattermost/login_spec.rb @@ -1,10 +1,10 @@ module QA feature 'logging in to Mattermost', :mattermost do scenario 'can use gitlab oauth' do - Runtime::Browser.visit(Page::Main::Login) do + Runtime::Browser.visit(:gitlab, Page::Main::Login) do Page::Main::Login.act { sign_in_using_credentials } - Runtime::Browser.visit(Page::Mattermost::Login) do + Runtime::Browser.visit(:mattermost, Page::Mattermost::Login) do Page::Mattermost::Login.act { sign_in_using_oauth } Page::Mattermost::Main.perform do |page| @@ -13,16 +13,5 @@ module QA end end end - - ## - # TODO, temporary workaround for gitlab-org/gitlab-qa#102. - # - after do - visit Runtime::Scenario.mattermost_address - reset_session! - - visit Runtime::Scenario.gitlab_address - reset_session! - end end end diff --git a/qa/qa/specs/features/project/create_spec.rb b/qa/qa/specs/features/project/create_spec.rb index 46c805d8b25..0b3accb848d 100644 --- a/qa/qa/specs/features/project/create_spec.rb +++ b/qa/qa/specs/features/project/create_spec.rb @@ -1,7 +1,7 @@ module QA feature 'create a new project', :core do scenario 'user creates a new project' do - Runtime::Browser.visit(Page::Main::Login) + Runtime::Browser.visit(:gitlab, Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } Scenario::Gitlab::Project::Create.perform do |project| diff --git a/qa/qa/specs/features/repository/clone_spec.rb b/qa/qa/specs/features/repository/clone_spec.rb index 18972c918a6..c5c24622657 100644 --- a/qa/qa/specs/features/repository/clone_spec.rb +++ b/qa/qa/specs/features/repository/clone_spec.rb @@ -9,7 +9,7 @@ module QA end before do - Runtime::Browser.visit(Page::Main::Login) + Runtime::Browser.visit(:gitlab, Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } Scenario::Gitlab::Project::Create.perform do |scenario| diff --git a/qa/qa/specs/features/repository/push_spec.rb b/qa/qa/specs/features/repository/push_spec.rb index 9ef532fd4a5..3da6fad6f17 100644 --- a/qa/qa/specs/features/repository/push_spec.rb +++ b/qa/qa/specs/features/repository/push_spec.rb @@ -2,7 +2,7 @@ module QA feature 'push code to repository', :core do context 'with regular account over http' do scenario 'user pushes code to the repository' do - Runtime::Browser.visit(Page::Main::Login) + Runtime::Browser.visit(:gitlab, Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } Scenario::Gitlab::Project::Create.perform do |scenario| -- cgit v1.2.1 From de7901ff59b9a4070b1355ecc2098b33e3674de9 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 11 Dec 2017 14:16:42 +0100 Subject: Fix minor Rubocop offenses in QA browser runtime --- qa/qa/page/base.rb | 4 +++- qa/qa/runtime/browser.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index 4e1a55337c9..49b16790337 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -13,8 +13,10 @@ module QA def wait(css = '.application', time: 60) Time.now.tap do |start| while Time.now - start < time - break if page.has_css?(css, wait: 5) puts "Waiting for `#{css} on `#{current_url}`" + + break if page.has_css?(css, wait: 5) + refresh end end diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb index e05dd9612df..96b3e144f99 100644 --- a/qa/qa/runtime/browser.rb +++ b/qa/qa/runtime/browser.rb @@ -79,7 +79,7 @@ module QA def perform(&block) visit(@address) - block.call if block_given? + yield if block_given? rescue raise if block.nil? -- cgit v1.2.1 From 2711d043b814a9feec859968cfc67e3eff770750 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 11 Dec 2017 14:40:03 +0000 Subject: Update browser.rb --- qa/qa/runtime/browser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb index 96b3e144f99..f95e4c78fcc 100644 --- a/qa/qa/runtime/browser.rb +++ b/qa/qa/runtime/browser.rb @@ -54,7 +54,7 @@ module QA Capybara.configure do |config| config.default_driver = :chrome config.javascript_driver = :chrome - config.default_max_wait_time = 4 + config.default_max_wait_time = 10 # https://github.com/mattheworiordan/capybara-screenshot/issues/164 config.save_path = 'tmp' end -- cgit v1.2.1 From 1bd0c0d05836bb88d29aff6c7708905ad666ebf1 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 11 Dec 2017 14:40:50 +0000 Subject: Update browser.rb --- qa/qa/runtime/browser.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb index f95e4c78fcc..6fb37fdfc7f 100644 --- a/qa/qa/runtime/browser.rb +++ b/qa/qa/runtime/browser.rb @@ -86,7 +86,7 @@ module QA # RSpec examples will take care of screenshots on their own # unless block.binding.receiver.is_a?(RSpec::Core::ExampleGroup) - Capybara::Screenshot.screenshot_and_save_page + screenshot_and_save_page end raise @@ -101,7 +101,7 @@ module QA # def clear! visit(@address) - Capybara.reset_session! + reset_session! end end end -- cgit v1.2.1 From d060b05f6331a8dd210aa601927f8ea1aac961b2 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 12 Dec 2017 12:32:26 +0100 Subject: Remove unused page from hashed storage QA scenario --- qa/qa/scenario/gitlab/admin/hashed_storage.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/qa/qa/scenario/gitlab/admin/hashed_storage.rb b/qa/qa/scenario/gitlab/admin/hashed_storage.rb index ac2cd549829..44604c6bc66 100644 --- a/qa/qa/scenario/gitlab/admin/hashed_storage.rb +++ b/qa/qa/scenario/gitlab/admin/hashed_storage.rb @@ -6,7 +6,6 @@ module QA def perform(*traits) raise ArgumentError unless traits.include?(:enabled) - Page::Main::Entry.act { visit_login_page } Page::Main::Login.act { sign_in_using_credentials } Page::Main::Menu.act { go_to_admin_area } Page::Admin::Menu.act { go_to_settings } -- cgit v1.2.1 From 9ac8bb08653a671415cd02da08b435a7b146b97f Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 12 Dec 2017 12:37:17 +0100 Subject: Remove noisy notification from QA base page --- qa/qa/page/base.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index 49b16790337..99eba02b6e3 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -13,8 +13,6 @@ module QA def wait(css = '.application', time: 60) Time.now.tap do |start| while Time.now - start < time - puts "Waiting for `#{css} on `#{current_url}`" - break if page.has_css?(css, wait: 5) refresh -- cgit v1.2.1