Commit 73be160c authored by Rémy Coutable's avatar Rémy Coutable

Make Page::Main::Login#sign_in_using_credentials gracefully bail out when user is already logged-in

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent b0fadeee
...@@ -26,53 +26,58 @@ module QA ...@@ -26,53 +26,58 @@ module QA
end end
def initialize def initialize
# The login page is usually the entry point for all the scenarios so
# we need to wait for the instance to start. That said, in some cases
# we are already logged-in so we check both cases here.
wait(max: 500) do wait(max: 500) do
page.has_css?('.application') page.has_css?('.login-page') ||
Page::Menu::Main.act { has_personal_area? }
end end
end end
def set_initial_password_if_present def sign_in_using_credentials
if page.has_content?('Change your password') # Don't try to log-in if we're already logged-in
fill_in :user_password, with: Runtime::User.password return if Page::Menu::Main.act { has_personal_area? }
fill_in :user_password_confirmation, with: Runtime::User.password
click_button 'Change your password' using_wait_time 0 do
set_initial_password_if_present
if Runtime::User.ldap_user?
sign_in_using_ldap_credentials
else
sign_in_using_gitlab_credentials
end
end end
end end
def sign_in_using_credentials def self.path
if Runtime::User.ldap_user? '/users/sign_in'
sign_in_using_ldap_credentials
else
sign_in_using_gitlab_credentials
end
end end
def sign_in_using_ldap_credentials private
using_wait_time 0 do
set_initial_password_if_present
click_link 'LDAP' def sign_in_using_ldap_credentials
click_link 'LDAP'
fill_in :username, with: Runtime::User.ldap_username fill_in :username, with: Runtime::User.ldap_username
fill_in :password, with: Runtime::User.ldap_password fill_in :password, with: Runtime::User.ldap_password
click_button 'Sign in' click_button 'Sign in'
end
end end
def sign_in_using_gitlab_credentials def sign_in_using_gitlab_credentials
using_wait_time 0 do click_link 'Standard' if page.has_content?('LDAP')
set_initial_password_if_present
click_link 'Standard' if page.has_content?('LDAP')
fill_in :user_login, with: Runtime::User.name fill_in :user_login, with: Runtime::User.name
fill_in :user_password, with: Runtime::User.password fill_in :user_password, with: Runtime::User.password
click_button 'Sign in' click_button 'Sign in'
end
end end
def self.path def set_initial_password_if_present
'/users/sign_in' return unless page.has_content?('Change your password')
fill_in :user_password, with: Runtime::User.password
fill_in :user_password_confirmation, with: Runtime::User.password
click_button 'Change your password'
end end
end end
end end
......
...@@ -55,7 +55,8 @@ module QA ...@@ -55,7 +55,8 @@ module QA
end end
def has_personal_area? def has_personal_area?
page.has_selector?('.qa-user-avatar') # No need to wait, either we're logged-in, or not.
using_wait_time(0) { page.has_selector?('.qa-user-avatar') }
end end
private private
......
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