diff --git a/RoboFile.php b/RoboFile.php index ac70104829..dfa61f0e39 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -291,6 +291,15 @@ public function runTests($opts = ['use-htaccess' => false, 'env' => 'desktop']) ->run() ->stopOnFail(); + $this->taskCodecept($pathToCodeception) + ->arg('--steps') + ->arg('--debug') + ->arg('--fail-fast') + ->arg('--env ' . $opts['env']) + ->arg('tests/acceptance/users_frontend.feature') + ->run() + ->stopOnFail(); + /* $this->taskCodecept($pathToCodeception) ->arg('--steps') ->arg('--debug') diff --git a/tests/_support/Page/Acceptance/Administrator/UserManagerPage.php b/tests/_support/Page/Acceptance/Administrator/UserManagerPage.php index 20c349ca83..825a6ea722 100644 --- a/tests/_support/Page/Acceptance/Administrator/UserManagerPage.php +++ b/tests/_support/Page/Acceptance/Administrator/UserManagerPage.php @@ -11,15 +11,27 @@ class UserManagerPage extends AdminPage public static $passwordField = ['id' => 'jform_password']; + public static $password1Field = ['id' => 'jform_password1']; + public static $password2Field = ['id' => 'jform_password2']; public static $emailField = ['id' => 'jform_email']; + + public static $email1Field = ['id' => 'jform_email1']; + + public static $email2Field = ['id' => 'jform_email2']; public static $filterSearch = ['id' => 'filter_search']; public static $iconSearch = ['class' => 'icon-search']; public static $title = ['id' => 'jform_title']; - + + public static $seeUserName = ['xpath' => ".//*[@id='userList']//*/tr[1]/td[3]"]; + + public static $seeName = ['xpath' => ".//*[@id='userList']//*/tr[1]/td[2]"]; + + public static $lastLoginDate = ['xpath' => ".//*[@id='userList']//*/tr[1]/td[8]"]; + public static $url = "administrator/index.php?option=com_users&view=users"; } diff --git a/tests/_support/Page/Acceptance/Site/Frontendlogin.php b/tests/_support/Page/Acceptance/Site/Frontendlogin.php new file mode 100644 index 0000000000..736746f727 --- /dev/null +++ b/tests/_support/Page/Acceptance/Site/Frontendlogin.php @@ -0,0 +1,19 @@ + 'modlgn-username']; + + public static $modlgnPasswd = ['id' => 'modlgn-passwd']; + + public static $btnGroup = ['class' => 'btn-group']; + + public static $btnPrimaryValidate = ['class' => 'btn-primary']; + + public static $mdlLogin = ['xpath' => ".//*[@id='aside']/div[2]/h3"]; + + +} diff --git a/tests/_support/Page/Acceptance/Site/Frontpage.php b/tests/_support/Page/Acceptance/Site/Frontpage.php new file mode 100644 index 0000000000..927916e59d --- /dev/null +++ b/tests/_support/Page/Acceptance/Site/Frontpage.php @@ -0,0 +1,11 @@ + 'alert-message']; + + public static $loginGreeting = ['class' => 'login-greeting']; +} diff --git a/tests/_support/Step/Acceptance/Administrator/User.php b/tests/_support/Step/Acceptance/Administrator/User.php index 6cec19bdfd..942a00cbb4 100644 --- a/tests/_support/Step/Acceptance/Administrator/User.php +++ b/tests/_support/Step/Acceptance/Administrator/User.php @@ -1,11 +1,12 @@ waitForText($message, 60, AdminPage::$systemMessageContainer); + $I->waitForText($message, TIMEOUT, AdminPage::$systemMessageContainer); $I->see($message, AdminPage::$systemMessageContainer); } @@ -380,7 +381,7 @@ public function iGotoTheOptionSetting() public function iSetAllowUserRegistrationAsAYes() { $I = $this; - $I->selectOptionInRadioField('Allow User Registration', 'Yes'); + $I->click(Locator::contains('label', 'Yes')); } /** @@ -393,13 +394,12 @@ public function iSaveTheSetting() } - /** * @Then I should be see the link Create an account in frontend */ public function iShouldBeSeeTheLinkCreateAnAccountInFrontend() { $I = $this; - $I->click(['class' => 'brand visible-desktop visible-tablet']); + $I->amOnPage('/'); } } diff --git a/tests/_support/Step/Acceptance/Site/users_frontend.php b/tests/_support/Step/Acceptance/Site/users_frontend.php new file mode 100644 index 0000000000..4c1cf30073 --- /dev/null +++ b/tests/_support/Step/Acceptance/Site/users_frontend.php @@ -0,0 +1,304 @@ +amOnPage(UserManagerPage::$url); + $I->clickToolbarButton('options'); + $I->click(Locator::contains('label', 'Yes')); + $I->clickToolbarButton('Save'); + } + + /** + * @Given there is no user with Username :arg1 or Email :arg2 + */ + public function thereIsNoUserWithUsernameOrEmail($username, $email) + { + $I = $this; + $I->amOnPage(UserManagerPage::$url); + $I->fillField(UserManagerPage::$filterSearch, $username); + $I->click(UserManagerPage::$iconSearch); + $I->see('No Matching Results'); + $I->fillField(UserManagerPage::$filterSearch, $email); + $I->click(UserManagerPage::$iconSearch); + $I->see('No Matching Results'); + } + + /** + * @When I press on the link :arg1 + */ + public function iPressOnTheLink($CreateAccount) + { + $I = $this; + $I->amOnPage(Frontpage::$url); + $I->click($CreateAccount); + $I->waitForText('User Registration', TIMEOUT); + } + + /** + * @When I create a user with fields Name :arg1, Uaername :arg1, Password :arg1 and Email :arg4 + */ + public function iCreateAUserWithFieldsNameUaernamePasswordAndEmail($name, $username, $password, $email) + { + $I = $this; + $I->fillField(UserManagerPage::$nameField, $name); + $I->fillField(UserManagerPage::$usernameField, $username); + $I->fillField(UserManagerPage::$password1Field, $password); + $I->fillField(UserManagerPage::$password2Field, $password); + $I->fillField(UserManagerPage::$email1Field, $email); + $I->fillField(UserManagerPage::$email2Field, $email); + } + + /** + * @When I press the :arg1 button + */ + public function iPressTheButton($register) + { + $I = $this; + $I->click($register); + } + + /** + * @Then I should see :arg1 message + */ + public function iShouldSeeMessage($message) + { + $I = $this; + $I->see($message, Frontpage::$alertMessage); + } + + /** + * @Then user is created + */ + public function userIsCreated() + { + $I = $this; + } + + /** + * @Given I am on the User Manager page + */ + public function iAmOnTheUserManagerPage() + { + $I = $this; + $I->amOnPage(UserManagerPage::$url); + } + + /** + * @When I search the user with user name :arg1 + */ + public function iSearchTheUserWithUserName($username) + { + $I = $this; + $I->waitForText('Users', TIMEOUT); + $I->fillField(UserManagerPage::$filterSearch, $username); + $I->click(UserManagerPage::$iconSearch); + } + + /** + * @Then I should see the user :arg1 + */ + public function iShouldSeeTheUser($username) + { + $I = $this; + $I->see($username, UserManagerPage::$seeUserName); + } + + /** + * @Given A not yet activated user with username :arg1 exists + */ + public function aNotYetActivatedUserWithUsernameExists($username) + { + $I = $this; + $I->amOnPage(UserManagerPage::$url); + $I->see($username, UserManagerPage::$seeName); + } + + /** + * @Given I am on a frontend page with a login module + */ + public function iAmOnAFrontendPageWithALoginModule() + { + $I = $this; + $I->amOnPage(Frontpage::$url); + $I->see('Login Form', Frontendlogin::$mdlLogin); + } + + /** + * @When I enter username :arg1 and password :arg1 into the login module + */ + public function iEnterUsernameAndPasswordIntoTheLoginModule($username, $password) + { + $I = $this; + $I->fillField(Frontendlogin::$modlgnUsername, $username); + $I->fillField(Frontendlogin::$modlgnPasswd, $password); + } + + /** + * @When I press on :arg1 + */ + public function iPressOnButton($login) + { + $I = $this; + $I->click($login); + } + + /** + * @Then I should see the :arg1 warning + */ + public function iShouldSeeTheWarning($warning) + { + $I = $this; + $I->see($warning, Frontpage::$alertMessage); + } + + /** + * @When I unblock the user :arg1 + */ + public function iUnblockTheUser($username) + { + $I = $this; + $I->fillField(UserManagerPage::$filterSearch, $username); + $I->click(UserManagerPage::$iconSearch); + $I->checkAllResults(); + $I->clickToolbarButton('unblock'); + } + + /** + * @When I activate the user :arg1 + */ + public function iActivateTheUser($username) + { + $I = $this; + $I->fillField(UserManagerPage::$filterSearch, $username); + $I->click(UserManagerPage::$iconSearch); + $I->checkAllResults(); + $I->clickToolbarButton('publish'); + } + + /** + * @When I login with user :arg1 with password :arg1 in frontend + */ + public function iLoginWithUserWithPasswordInFrontend($username, $password) + { + $I = $this; + $I->amOnPage(Frontpage::$url); + $I->fillField(Frontendlogin::$modlgnUsername, $username); + $I->fillField(Frontendlogin::$modlgnPasswd, $password); + $I->click('Log in'); + } + + /** + * @Then I should see the message :arg1 + */ + public function iShouldSeeTheMessage($message) + { + $I = $this; + $I->see($message, Frontpage::$loginGreeting); + } + + /** + * @Given I am logged in into the frontend as user :arg1 with password :arg2 + */ + public function iAmLoggedInIntoTheFrontendAsUser($username, $password) + { + $I = $this; + $I->amOnPage(Frontpage::$url); + $I->fillField(Frontendlogin::$modlgnUsername, $username); + $I->fillField(Frontendlogin::$modlgnPasswd, $password); + $I->click('Log in'); + } + + /** + * @When I press on the :arg1 button + */ + public function iPressOnTheButton($editProfile) + { + $I = $this; + $I->amOnPage(Frontendlogin::$profile); + $I->click($editProfile); + } + + /** + * @When I change the name to :arg1 + */ + public function iChangeTheNameTo($name) + { + $I = $this; + $I->waitForText('Edit Your Profile', TIMEOUT); + $I->fillField(UserManagerPage::$nameField, $name); + } + + /** + * @When I press on :arg1 button + */ + public function iPressOn($submit) + { + $I = $this; + $I->click($submit); + } + + /** + * @When I search the user with name :arg1 + */ + public function iSearchTheUserWithName($name) + { + $I = $this; + $I->fillField(UserManagerPage::$filterSearch, $name); + $I->click(UserManagerPage::$iconSearch); + } + + /** + * @Then I should see the name :name + */ + public function iShouldSeeTheName($name) + { + $I = $this; + $I->see($name, UserManagerPage::$seeName); + } + + /** + * @Given Needs to user :arg1 logged in at least once + */ + public function needsToUserLoggedInAtLeastOnce($arg1) + { + // Do nothing as user will be already logged in previous tests. + $I = $this; + } + + /** + * @When I login as a super admin from backend + */ + public function iLoginAsASuperAdminFromBackend() + { + $I = $this; + $I->amOnPage(UserManagerPage::$url); + } + + /** + * @Then I should see last login date for :name + */ + public function iShouldSeeLastLoginDate($name) + { + $I = $this; + + // @TODO needs to create common function to use search. + $I->fillField(UserManagerPage::$filterSearch, $name); + $I->click(UserManagerPage::$iconSearch); + + // Just make sure that we don't see "Never". + $I->dontSee('Never', UserManagerPage::$lastLoginDate); + } +} diff --git a/tests/acceptance.suite.dist.yml b/tests/acceptance.suite.dist.yml index b28adc8165..085cf6a988 100644 --- a/tests/acceptance.suite.dist.yml +++ b/tests/acceptance.suite.dist.yml @@ -16,7 +16,7 @@ modules: browser: 'firefox' window_size: 1024x768 capabilities: - unexpectedAlertBehaviour: 'accept' + unexpectedAlertBehaviour: 'accept' username: 'admin' # UserName for the Administrator password: 'admin' # Password for the Administrator database host: 'localhost' # place where the Application is Hosted #server Address diff --git a/tests/acceptance/users.feature b/tests/acceptance/users.feature index db5864ad08..f02134f042 100644 --- a/tests/acceptance/users.feature +++ b/tests/acceptance/users.feature @@ -30,10 +30,10 @@ Feature: users When I block the user Then I should see the "User blocked." message -# Scenario: Unblock user -# Given I have a blocked user with user name "register" -# When I unblock the user -# Then I should see the "User enabled." message + Scenario: Unblock user + Given I have a blocked user with user name "register" + When I unblock the user + Then I should see the "User enabled." message Scenario: Delete user Given I have a user with user name "Editor" diff --git a/tests/acceptance/users_frontend.feature b/tests/acceptance/users_frontend.feature new file mode 100644 index 0000000000..8245075926 --- /dev/null +++ b/tests/acceptance/users_frontend.feature @@ -0,0 +1,51 @@ +Feature: Users Frontend + In order to manage users account in the web + As a user + I need to check user login and registration in joomla! CMS + + Background: + Given Joomla CMS is installed + When Login into Joomla administrator with username "admin" and password "admin" + Then I see administrator dashboard + + Scenario: Create user from frontend (index.php?option=com_users) + Given that user registration is enabled + And there is no user with Username "patel" or Email "patel@gmail.com" + When I press on the link "Create an account" + And I create a user with fields Name "patel", Uaername "patel", Password "patel" and Email "patel@gmail.com" + And I press the "Register" button + Then I should see "Could not instantiate mail function." message + + Scenario: check the created user in the backend + Given I am on the User Manager page + And I search the user with user name "patel" + Then I should see the user "patel" + + Scenario: User can not login, if the account has not been activated + Given A not yet activated user with username "patel" exists + And I am on a frontend page with a login module + When I enter username "patel" and password "patel" into the login module + And I press on "Log in" + Then I should see the "Login denied! Your account has either been blocked or you have not activated it yet." warning + + Scenario: Check if block and activation are working + Given I am on the User Manager page + When I unblock the user "patel" + And I activate the user "patel" + And I login with user "patel" with password "patel" in frontend + Then I should see the message "Hi patel," + + Scenario: Profile changes done in the frontend are available in the backend + Given I am logged in into the frontend as user "patel" with password "patel" + When I press on the "Edit Profile" button + And I change the name to "patidar" + And I press on "Submit" button + And I should see "Profile successfully saved." message + And I am on the User Manager page + And I search the user with name "patidar" + Then I should see the name "patidar" + + Scenario: Test last login date + Given Needs to user "patel" logged in at least once + When I login as a super admin from backend + Then I should see last login date for "patidar"