Commit 0430524b authored by Grzegorz Bizon's avatar Grzegorz Bizon

WIP Handle domain sessions better in QA test scenario

[ci skip]
parent 9799d363
......@@ -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
##
......
......@@ -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
......@@ -3,20 +3,8 @@ module QA
module Main
class Entry < Page::Base
def visit_login_page
wait(time: 500) do
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
end
end
end
......
......@@ -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
module Runtime
module Browser
extend self
def perform
configure_rspec!
configure_capybara!
end
def session(address, &block)
configure!
page.visit(address)
block.call(page)
def configure_rspec!
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = 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
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
raise
end
config.order = :random
Kernel.srand config.seed
config.formatter = :documentation
config.color = true
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
......
......@@ -8,7 +8,6 @@ module QA
include Bootable
def perform(address, *files)
Specs::Config.act { configure_capybara! }
Runtime::Scenario.define(:gitlab_address, address)
##
......
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 }
......
module QA
feature 'logging in to Mattermost', :mattermost do
scenario 'can use gitlab oauth' do
Page::Main::Entry.act { visit_login_page }
Runtime::Browser.session(Page::Gitlab::Login) do
Page::Main::Login.act { sign_in_using_credentials }
Runtime::Browser.session(Page::Mattermost::Login) do
Page::Mattermost::Login.act { sign_in_using_oauth }
Page::Mattermost::Main.perform do |page|
......@@ -10,4 +12,6 @@ module QA
end
end
end
end
end
end
......@@ -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?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment