Commit 1b0274bf authored by Mark Lapierre's avatar Mark Lapierre Committed by Sanad Liaquat

Add login flow

Adds a Flow module for frequently used sequences of actions

Adds a login flow, including for logging in, performing some actions
and then logging out.

Updates a test as an example of how to use the login flow.

Adds a class method `QA::Resource::User.admin` to provide access
to the admin user's details (include username/password needed to
sign in)
parent 9b076234
# Flows in GitLab QA
Flows are frequently used sequences of actions. They are a higher level
of abstraction than page objects. Flows can include multiple page objects,
or any other relevant code.
For example, the sign in flow encapsulates two steps that are included
in every browser UI test.
```ruby
# QA::Flow::Login
def sign_in(as: nil)
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform { |login| login.sign_in_using_credentials(user: as) }
end
# When used in a test
it 'performs a test after signing in as the default user' do
Flow::Login.sign_in
# Perform the test
end
```
`QA::Flow::Login` provides an even more useful flow, allowing a test to easily switch users.
```ruby
# QA::Flow::Login
def while_signed_in(as: nil)
Page::Main::Menu.perform(&:sign_out_if_signed_in)
sign_in(as: as)
yield
Page::Main::Menu.perform(&:sign_out)
end
# When used in a test
it 'performs a test as one user and verifies as another' do
user1 = Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_1, Runtime::Env.gitlab_qa_password_1)
user2 = Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_2, Runtime::Env.gitlab_qa_password_2)
Flow::Login.while_signed_in(as: user1) do
# Perform some setup as user1
end
Flow::Login.sign_in(as: user2)
# Perform the rest of the test as user2
end
```
......@@ -131,6 +131,7 @@ Continued reading:
- [Style Guide](style_guide.md)
- [Best Practices](best_practices.md)
- [Testing with feature flags](feature_flags.md)
- [Flows](flows.md)
## Where can I ask for help?
......
......@@ -9,6 +9,14 @@ require_relative '../lib/gitlab/utils'
require_relative '../config/initializers/0_inject_enterprise_edition_module'
module QA
##
# Helper classes to represent frequently used sequences of actions
# (e.g., login)
#
module Flow
autoload :Login, 'qa/flow/login'
end
##
# GitLab QA runtime classes, mostly singletons.
#
......
# frozen_string_literal: true
module QA
module Flow
module Login
module_function
def while_signed_in(as: nil)
Page::Main::Menu.perform(&:sign_out_if_signed_in)
sign_in(as: as)
yield
Page::Main::Menu.perform(&:sign_out)
end
def while_signed_in_as_admin
while_signed_in(as: Runtime::User.admin) do
yield
end
end
def sign_in(as: nil)
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform { |login| login.sign_in_using_credentials(user: as) }
end
def sign_in_as_admin
sign_in(as: Runtime::User.admin)
end
end
end
end
......@@ -5,6 +5,10 @@ module QA
module User
extend self
def admin
Struct.new(:username, :password).new(admin_username, admin_password)
end
def default_username
'root'
end
......
......@@ -39,7 +39,7 @@ module QA
]
before(:all) do
login
Flow::Login.sign_in_as_admin
@group = Resource::Group.fabricate_via_api! do |group|
group.path = 'template-group'
......@@ -71,16 +71,15 @@ module QA
end
after(:all) do
login unless Page::Main::Menu.perform(&:signed_in?)
remove_group_file_template_if_set
Page::Main::Menu.perform(&:sign_out)
Flow::Login.while_signed_in_as_admin do
remove_group_file_template_if_set
end
end
templates.each do |template|
it "creates file via custom #{template[:type]} file template" do
login
Flow::Login.sign_in_as_admin
set_file_template_if_not_already_set
@project.visit!
......@@ -101,11 +100,6 @@ module QA
end
end
def login
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_admin_credentials)
end
def set_file_template_if_not_already_set
api_client = Runtime::API::Client.new(:gitlab)
response = get Runtime::API::Request.new(api_client, "/groups/#{@group.id}").url
......
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