From 6a12da2bf180d7f0cf4aeecec830a791ad3dc0fd Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 29 Jul 2022 10:04:13 +0200 Subject: [PATCH] MOBILE-4034 behat: Add tests for complete profile and change pwd --- .../tests/behat/behat_app.php | 6 ++- .../login/tests/behat/basic_usage.feature | 49 +++++++++++++++++ .../user/tests/behat/basic_usage.feature | 53 +++++++++++++++++++ 3 files changed, 106 insertions(+), 2 deletions(-) create mode 100755 src/core/features/user/tests/behat/basic_usage.feature diff --git a/local_moodleappbehat/tests/behat/behat_app.php b/local_moodleappbehat/tests/behat/behat_app.php index 59ece39db..e7f0ed2f0 100644 --- a/local_moodleappbehat/tests/behat/behat_app.php +++ b/local_moodleappbehat/tests/behat/behat_app.php @@ -273,8 +273,10 @@ class behat_app extends behat_app_helper { // Wait until the main page appears. $this->spin( function($context, $args) { - $mainmenu = $context->getSession()->getPage()->find('xpath', '//page-core-mainmenu'); - if ($mainmenu) { + $initialpage = $context->getSession()->getPage()->find('xpath', '//page-core-mainmenu') ?? + $context->getSession()->getPage()->find('xpath', '//page-core-login-change-password') ?? + $context->getSession()->getPage()->find('xpath', '//page-core-user-complete-profile'); + if ($initialpage) { return true; } throw new DriverException('Moodle App main page not loaded after login'); diff --git a/src/core/features/login/tests/behat/basic_usage.feature b/src/core/features/login/tests/behat/basic_usage.feature index 62ffc00fe..d92501232 100755 --- a/src/core/features/login/tests/behat/basic_usage.feature +++ b/src/core/features/login/tests/behat/basic_usage.feature @@ -90,3 +90,52 @@ Feature: Test basic usage of login in app | minimumversion | 11.0.0 | tool_mobile | When I enter the app Then I should find "App update required" in the app + + Scenario: Force password change + Given I force a password change for user "student1" + When I enter the app + And I log in as "student1" + Then I should find "Change your password" in the app + And I should find "You must change your password to proceed." in the app + + When I press "Change password" in the app + Then the app should have opened a browser tab with url "webserver" + + When I close the browser tab opened by the app + Then I should find "If you didn't change your password correctly, you'll be asked to do it again." in the app + But I should not find "Change your password" in the app + + When I press "Reconnect" in the app + Then I should find "Change your password" in the app + But I should not find "Reconnect" in the app + + When I press "Switch account" in the app + Then I should find "Accounts" in the app + And I should find "david student" in the app + + When I press "david student" in the app + Then I should find "Change your password" in the app + But I should not find "Reconnect" in the app + + When I press "Change password" in the app + Then the app should have opened a browser tab with url "webserver" + + When I switch to the browser tab opened by the app + And I set the field "username" to "student1" + And I set the field "password" to "student1" + And I click on "Log in" "button" + Then I should see "You must change your password to proceed" + + When I set the field "Current password" to "student1" + And I set the field "New password" to "NewPassword1*" + And I set the field "New password (again)" to "NewPassword1*" + And I click on "Sign out everywhere" "checkbox" + And I click on "Save changes" "button" + Then I should see "Password has been changed" + + When I close the browser tab opened by the app + Then I should find "If you didn't change your password correctly, you'll be asked to do it again." in the app + But I should not find "Change your password" in the app + + When I press "Reconnect" in the app + Then I should find "Acceptance test site" in the app diff --git a/src/core/features/user/tests/behat/basic_usage.feature b/src/core/features/user/tests/behat/basic_usage.feature new file mode 100755 index 000000000..4aa6b8401 --- /dev/null +++ b/src/core/features/user/tests/behat/basic_usage.feature @@ -0,0 +1,53 @@ +@core @core_user @app @javascript +Feature: Test basic usage of user features + + Background: + Given the following "users" exist: + | username | firstname | lastname | + | student1 | Student | Student | + + Scenario: Complete missing fields + Given the following "custom profile fields" exist: + | datatype | shortname | name | required | + | text | food | Favourite food | 1 | + When I enter the app + And I log in as "student1" + Then I should find "Complete your profile" in the app + And I should find "Before you continue, please fill in the required fields in your user profile." in the app + + When I press "Complete profile" in the app + Then the app should have opened a browser tab with url "webserver" + + When I close the browser tab opened by the app + Then I should find "If you didn't complete your profile correctly, you'll be asked to do it again." in the app + But I should not find "Complete your profile" in the app + + When I press "Reconnect" in the app + Then I should find "Complete your profile" in the app + But I should not find "Reconnect" in the app + + When I press "Switch account" in the app + Then I should find "Accounts" in the app + And I should find "Student Student" in the app + + When I press "Student Student" in the app + Then I should find "Complete your profile" in the app + But I should not find "Reconnect" in the app + + When I press "Complete profile" in the app + Then the app should have opened a browser tab with url "webserver" + + When I switch to the browser tab opened by the app + And I set the field "username" to "student1" + And I set the field "password" to "student1" + And I click on "Log in" "button" + And I set the field "Favourite food" to "Pasta" + And I click on "Update profile" "button" + Then I should see "Changes saved" + + When I close the browser tab opened by the app + Then I should find "If you didn't complete your profile correctly, you'll be asked to do it again." in the app + But I should not find "Complete your profile" in the app + + When I press "Reconnect" in the app + Then I should find "Acceptance test site" in the app