From 633c71251de10a516fc85beebc6df9929ccb1b44 Mon Sep 17 00:00:00 2001 From: Mark Lapierre Date: Thu, 13 Sep 2018 17:51:34 -0400 Subject: Allow registration when LDAP is enabled Update the login page object and related code so that a user can be registered when LDAP is enabled --- qa/qa/factory/resource/user.rb | 5 +++- qa/qa/page/base.rb | 4 +++ qa/qa/page/main/login.rb | 29 ++++++++++++++++----- .../browser_ui/1_manage/login/register_spec.rb | 30 ++++++++++++++++++++++ 4 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 qa/qa/specs/features/browser_ui/1_manage/login/register_spec.rb (limited to 'qa') diff --git a/qa/qa/factory/resource/user.rb b/qa/qa/factory/resource/user.rb index eac2a873bd5..34b52223b2d 100644 --- a/qa/qa/factory/resource/user.rb +++ b/qa/qa/factory/resource/user.rb @@ -37,7 +37,10 @@ module QA product(:password) { |factory| factory.password } def fabricate! - Page::Menu::Main.perform { |main| main.sign_out } + # Don't try to log-out if we're not logged-in + if Page::Menu::Main.act { has_personal_area?(wait: 0) } + Page::Menu::Main.perform { |main| main.sign_out } + end if credentials_given? Page::Main::Login.perform do |login| diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index 30e35bf7abb..a87536671c6 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -76,6 +76,10 @@ module QA find_element(name).set(content) end + def has_element?(name) + has_css?(element_selector_css(name)) + end + def within_element(name) page.within(element_selector_css(name)) do yield diff --git a/qa/qa/page/main/login.rb b/qa/qa/page/main/login.rb index e9e49964e63..89542b49d0e 100644 --- a/qa/qa/page/main/login.rb +++ b/qa/qa/page/main/login.rb @@ -23,6 +23,7 @@ module QA view 'app/views/devise/shared/_tabs_ldap.html.haml' do element :ldap_tab element :standard_tab + element :register_tab end view 'app/views/devise/shared/_tabs_normal.html.haml' do @@ -35,7 +36,7 @@ module QA # 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 - page.has_css?('.login-page') || + has_css?('.login-page') || Page::Menu::Main.act { has_personal_area?(wait: 0) } end end @@ -78,12 +79,28 @@ module QA '/users/sign_in' end + def has_sign_in_tab? + has_element?(:sign_in_tab) + end + + def has_ldap_tab? + has_element?(:ldap_tab) + end + + def has_standard_tab? + has_element?(:standard_tab) + end + def sign_in_tab? - page.has_button?('Sign in') + has_css?(".active", text: 'Sign in') end def ldap_tab? - page.has_link?('LDAP') + has_css?(".active", text: 'LDAP') + end + + def standard_tab? + has_css?(".active", text: 'Standard') end def switch_to_sign_in_tab @@ -113,8 +130,8 @@ module QA end def sign_in_using_gitlab_credentials(user) - switch_to_sign_in_tab unless sign_in_tab? - switch_to_standard_tab if ldap_tab? + switch_to_sign_in_tab if has_sign_in_tab? + switch_to_standard_tab if has_standard_tab? fill_element :login_field, user.username fill_element :password_field, user.password @@ -122,7 +139,7 @@ module QA end def set_initial_password_if_present - return unless page.has_content?('Change your password') + return unless has_content?('Change your password') fill_element :password_field, Runtime::User.password fill_element :password_confirmation, Runtime::User.password diff --git a/qa/qa/specs/features/browser_ui/1_manage/login/register_spec.rb b/qa/qa/specs/features/browser_ui/1_manage/login/register_spec.rb new file mode 100644 index 00000000000..478a5cb9c4c --- /dev/null +++ b/qa/qa/specs/features/browser_ui/1_manage/login/register_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module QA + shared_examples 'registration and login' do + it 'user registers and logs in' do + Runtime::Browser.visit(:gitlab, Page::Main::Login) + + Factory::Resource::User.fabricate! + + # TODO, since `Signed in successfully` message was removed + # this is the only way to tell if user is signed in correctly. + # + Page::Menu::Main.perform do |menu| + expect(menu).to have_personal_area + end + end + end + + context :manage do + describe 'standard' do + it_behaves_like 'registration and login' + end + end + + context :manage, :orchestrated, :ldap do + describe 'while LDAP is enabled' do + it_behaves_like 'registration and login' + end + end +end -- cgit v1.2.3