diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-11-17 14:48:52 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-11-17 15:19:42 +0100 |
commit | 0430524bfea1700da34b78d7d323c69bb7f715e6 (patch) | |
tree | 35823ef9c568c3755b53e92148bc6bab88bb2c88 /qa | |
parent | 9799d363db7e54f615853b5e1428453ff8bbc2da (diff) | |
download | gitlab-ce-0430524bfea1700da34b78d7d323c69bb7f715e6.tar.gz |
WIP Handle domain sessions better in QA test scenario
[ci skip]
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa.rb | 1 | ||||
-rw-r--r-- | qa/qa/page/base.rb | 14 | ||||
-rw-r--r-- | qa/qa/page/main/entry.rb | 16 | ||||
-rw-r--r-- | qa/qa/runtime/browser.rb (renamed from qa/qa/specs/config.rb) | 59 | ||||
-rw-r--r-- | qa/qa/scenario/entrypoint.rb | 1 | ||||
-rw-r--r-- | qa/qa/specs/features/login/standard_spec.rb | 2 | ||||
-rw-r--r-- | qa/qa/specs/features/mattermost/login_spec.rb | 14 | ||||
-rw-r--r-- | qa/qa/specs/runner.rb | 2 |
8 files changed, 61 insertions, 48 deletions
@@ -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/specs/config.rb b/qa/qa/runtime/browser.rb index bce7923e52d..b27f5676108 100644 --- a/qa/qa/specs/config.rb +++ b/qa/qa/runtime/browser.rb @@ -3,37 +3,45 @@ 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 + module Runtime + module Browser + extend self - def configure_rspec! - RSpec.configure do |config| - config.expect_with :rspec do |expectations| - expectations.include_chain_clauses_in_custom_matcher_descriptions = true - end + def session(address, &block) + configure! + page.visit(address) - config.mock_with :rspec do |mocks| - mocks.verify_partial_doubles = true - end + block.call(page) - config.order = :random - Kernel.srand config.seed - config.formatter = :documentation - config.color = true + 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_capybara! + def configure! + return if Capybara.drivers.include?(:chrome) + Capybara.register_driver :chrome do |app| capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( 'chromeOptions' => { @@ -52,8 +60,7 @@ module QA Capybara.configure do |config| config.default_driver = :chrome config.javascript_driver = :chrome - config.default_max_wait_time = 10 - + config.default_max_wait_time = 4 # https://github.com/mattheworiordan/capybara-screenshot/issues/164 config.save_path = 'tmp' 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/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? |