Commit dbfeef25 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Use QA browser to navigate to pages and handle sessions

[ci skip]
parent 67c572ba
...@@ -38,6 +38,25 @@ module QA ...@@ -38,6 +38,25 @@ module QA
yield if block_given? yield if block_given?
end 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 end
end end
...@@ -2,11 +2,7 @@ module QA ...@@ -2,11 +2,7 @@ module QA
module Page module Page
module Main module Main
class Entry < Page::Base class Entry < Page::Base
def visit_login_page # TODO remove this class
wait(time: 500) do
visit("#{Runtime::Scenario.gitlab_address}/users/sign_in")
end
end
end end
end end
end end
......
...@@ -2,6 +2,14 @@ module QA ...@@ -2,6 +2,14 @@ module QA
module Page module Page
module Main module Main
class Login < Page::Base 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 def sign_in_using_credentials
if page.has_content?('Change your password') if page.has_content?('Change your password')
fill_in :user_password, with: Runtime::User.password fill_in :user_password, with: Runtime::User.password
......
...@@ -2,8 +2,8 @@ module QA ...@@ -2,8 +2,8 @@ module QA
module Page module Page
module Mattermost module Mattermost
class Login < Page::Base class Login < Page::Base
def initialize def self.address
visit(Runtime::Scenario.mattermost_address + '/login') Runtime::Scenario.mattermost_address + '/login'
end end
def sign_in_using_oauth def sign_in_using_oauth
......
...@@ -8,14 +8,18 @@ module QA ...@@ -8,14 +8,18 @@ module QA
module Browser module Browser
extend self extend self
def session(address, &block) def visit(entry, &block)
address = entry.is_a?(String) ? entry : entry.address
configure! configure!
page.visit(address) page.visit(address)
if block_given?
block.call(page) block.call(page)
page.visit(address) page.visit(address)
reset_domain_session! reset_domain_session!
end
rescue rescue
# RSpec examples will take care of screenshots on their own # RSpec examples will take care of screenshots on their own
# #
...@@ -26,6 +30,10 @@ module QA ...@@ -26,6 +30,10 @@ module QA
raise raise
end end
##
# Current session, when Capybara::DSL is included `page` method is
# mixed in as well.
#
def page def page
Capybara.current_session Capybara.current_session
end end
......
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
Page::Main::Entry.act { visit_login_page } Runtime::Browser.visit(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
Page::Main::Entry.act { visit_login_page } Runtime::Browser.visit(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.session(Page::Gitlab::Login) do Runtime::Browser.visit(Page::Gitlab::Login) do
Page::Main::Login.act { sign_in_using_credentials } 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::Login.act { sign_in_using_oauth }
Page::Mattermost::Main.perform do |page| Page::Mattermost::Main.perform do |page|
......
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
Page::Main::Entry.act { visit_login_page } Runtime::Browser.visit(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
Page::Main::Entry.act { visit_login_page } Runtime::Browser.visit(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
Page::Main::Entry.act { visit_login_page } Runtime::Browser.visit(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