Commit b80dc884 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Decouple subject's address from page objects in QA

parent 86aa7ac1
...@@ -22,10 +22,6 @@ module QA ...@@ -22,10 +22,6 @@ module QA
yield if block_given? yield if block_given?
end end
def self.address
raise NotImplementedError
end
def scroll_to(selector, text: nil) def scroll_to(selector, text: nil)
page.execute_script <<~JS page.execute_script <<~JS
var elements = Array.from(document.querySelectorAll('#{selector}')); var elements = Array.from(document.querySelectorAll('#{selector}'));
...@@ -40,6 +36,10 @@ module QA ...@@ -40,6 +36,10 @@ module QA
page.within(selector) { yield } if block_given? page.within(selector) { yield } if block_given?
end end
def self.path
raise NotImplementedError
end
end end
end end
end end
...@@ -18,8 +18,8 @@ module QA ...@@ -18,8 +18,8 @@ module QA
click_button 'Sign in' click_button 'Sign in'
end end
def self.address def self.path
Runtime::Scenario.gitlab_address + '/users/sign_in' '/users/sign_in'
end end
end end
end end
......
...@@ -10,8 +10,8 @@ module QA ...@@ -10,8 +10,8 @@ module QA
end end
end end
def self.address def self.path
Runtime::Scenario.gitlab_address + '/login' '/login'
end end
end end
end end
......
...@@ -12,14 +12,25 @@ module QA ...@@ -12,14 +12,25 @@ module QA
self.class.configure! self.class.configure!
end 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) session.perform(&block)
end end
end end
def self.visit(page, &block) def self.visit(address, page, &block)
new.visit(page, &block) new.visit(address, page, &block)
end end
def self.configure! def self.configure!
...@@ -52,10 +63,17 @@ module QA ...@@ -52,10 +63,17 @@ module QA
class Session class Session
include Capybara::DSL include Capybara::DSL
attr_reader :address def initialize(instance, page = nil)
@instance = instance
@address = host + page&.path
end
def initialize(page) def host
@address = page.is_a?(String) ? page : page.address if @instance.is_a?(Symbol)
Runtime::Scenario.send("#{@instance}_address")
else
@instance.to_s
end
end end
def perform(&block) def perform(&block)
......
module QA module QA
feature 'standard user login', :core do feature 'standard user login', :core do
scenario 'user logs in using credentials' 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 } Page::Main::Login.act { sign_in_using_credentials }
# TODO, since `Signed in successfully` message was removed # TODO, since `Signed in successfully` message was removed
......
module QA module QA
feature 'create a new group', :mattermost do feature 'create a new group', :mattermost do
scenario 'creating a group with a mattermost team' 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::Login.act { sign_in_using_credentials }
Page::Main::Menu.act { go_to_groups } Page::Main::Menu.act { go_to_groups }
......
module QA module QA
feature 'logging in to Mattermost', :mattermost do feature 'logging in to Mattermost', :mattermost do
scenario 'can use gitlab oauth' 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 } 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::Login.act { sign_in_using_oauth }
Page::Mattermost::Main.perform do |page| Page::Mattermost::Main.perform do |page|
...@@ -13,16 +13,5 @@ module QA ...@@ -13,16 +13,5 @@ module QA
end end
end 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
end end
module QA module QA
feature 'create a new project', :core do feature 'create a new project', :core do
scenario 'user creates a new project' 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 } Page::Main::Login.act { sign_in_using_credentials }
Scenario::Gitlab::Project::Create.perform do |project| Scenario::Gitlab::Project::Create.perform do |project|
......
...@@ -9,7 +9,7 @@ module QA ...@@ -9,7 +9,7 @@ module QA
end end
before do before do
Runtime::Browser.visit(Page::Main::Login) Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.act { sign_in_using_credentials } Page::Main::Login.act { sign_in_using_credentials }
Scenario::Gitlab::Project::Create.perform do |scenario| Scenario::Gitlab::Project::Create.perform do |scenario|
......
...@@ -2,7 +2,7 @@ module QA ...@@ -2,7 +2,7 @@ module QA
feature 'push code to repository', :core do feature 'push code to repository', :core do
context 'with regular account over http' do context 'with regular account over http' do
scenario 'user pushes code to the repository' 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 } Page::Main::Login.act { sign_in_using_credentials }
Scenario::Gitlab::Project::Create.perform do |scenario| Scenario::Gitlab::Project::Create.perform do |scenario|
......
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