diff --git a/local_moodleappbehat/tests/behat/behat_app.php b/local_moodleappbehat/tests/behat/behat_app.php index 3ddc2b583..ceda8b943 100644 --- a/local_moodleappbehat/tests/behat/behat_app.php +++ b/local_moodleappbehat/tests/behat/behat_app.php @@ -99,15 +99,29 @@ class behat_app extends behat_app_helper { * @Then I wait the app to restart */ public function i_wait_the_app_to_restart() { - if ($this->runtime_js('hasInitialized()')) { - // Already initialized. - return; - } - // Prepare testing runtime again. $this->prepare_browser(); } + /** + * @Then I log out in the app + * + * @param bool $force If force logout or not. + */ + public function i_log_out_in_app($force = true) { + $options = json_encode([ + 'forceLogout' => $force, + ]); + + $result = $this->zone_js("sites.logout($options)"); + + if ($result !== 'OK') { + throw new DriverException('Error on log out - ' . $result); + } + + $this->i_wait_the_app_to_restart(); + } + /** * Finds elements in the app. * diff --git a/local_moodleappbehat/tests/behat/behat_app_helper.php b/local_moodleappbehat/tests/behat/behat_app_helper.php index 41f9972f2..3142ce5f9 100644 --- a/local_moodleappbehat/tests/behat/behat_app_helper.php +++ b/local_moodleappbehat/tests/behat/behat_app_helper.php @@ -280,6 +280,11 @@ class behat_app_helper extends behat_base { * @throws DriverException If the app fails to load properly */ protected function prepare_browser(array $options = []) { + if ($this->evaluate_script('window.behat') && $this->runtime_js('hasInitialized()')) { + // Already initialized. + return; + } + $restart = false; if (!$this->apprunning) { @@ -510,6 +515,8 @@ class behat_app_helper extends behat_base { $successXPath = '//page-core-mainmenu'; } + $this->i_log_out_in_app(false); + $this->handle_url($url, $successXPath); } diff --git a/src/core/features/login/tests/behat/basic_usage.feature b/src/core/features/login/tests/behat/basic_usage.feature index 136ef3f1d..62ffc00fe 100755 --- a/src/core/features/login/tests/behat/basic_usage.feature +++ b/src/core/features/login/tests/behat/basic_usage.feature @@ -41,9 +41,7 @@ Feature: Test basic usage of login in app Scenario: Add a non existing account When I enter the app And I log in as "student1" - And I press the user menu button in the app - And I press "Log out" in the app - And I wait the app to restart + When I log out in the app And I press "Add" in the app And I set the field "Your site" to "Wrong Site Address" in the app And I press enter in the app @@ -62,11 +60,16 @@ Feature: Test basic usage of login in app Then I should find "Cannot connect" in the app And I should find "Wrong Site Address" in the app + Scenario: Log out from the app + Given I entered the app as "student1" + And I press the user menu button in the app + When I press "Log out" in the app + And I wait the app to restart + Then the header should be "Accounts" in the app + Scenario: Delete an account Given I entered the app as "student1" - When I press the user menu button in the app - And I press "Log out" in the app - And I wait the app to restart + When I log out in the app Then I should find "Acceptance test site" in the app And I press "Edit accounts list" in the app And I press "Remove account" near "Acceptance test site" in the app @@ -74,14 +77,14 @@ Feature: Test basic usage of login in app Then I should find "Connect to Moodle" in the app But I should not find "Acceptance test site" in the app - Scenario: Require minium version of the app for a site - + Scenario: Require minium (previous) version of the app for a site # Log in with a previous required version Given the following config values are set as admin: | minimumversion | 3.8.1 | tool_mobile | When I enter the app Then I should not find "App update required" in the app + Scenario: Require minium (future) version of the app for a site # Log in with a future required version Given the following config values are set as admin: | minimumversion | 11.0.0 | tool_mobile | diff --git a/src/core/services/sites.ts b/src/core/services/sites.ts index f28d5c44a..15bce3bba 100644 --- a/src/core/services/sites.ts +++ b/src/core/services/sites.ts @@ -1278,7 +1278,7 @@ export class CoreSitesProvider { /** * Logout the user. * - * @param forceLogout If true, site will be marked as logged out, no matter the value tool_mobile_forcelogout. + * @param options Logout options. * @return Promise resolved when the user is logged out. */ async logout(options: CoreSitesLogoutOptions = {}): Promise { diff --git a/src/testing/services/behat-runtime.ts b/src/testing/services/behat-runtime.ts index d8448e035..b9c971d2b 100644 --- a/src/testing/services/behat-runtime.ts +++ b/src/testing/services/behat-runtime.ts @@ -28,6 +28,7 @@ import { CoreDom } from '@singletons/dom'; import { IonRefresher } from '@ionic/angular'; import { CoreCoursesDashboardPage } from '@features/courses/pages/dashboard/dashboard'; import { Injectable } from '@angular/core'; +import { CoreSites, CoreSitesProvider } from '@services/sites'; /** * Behat runtime servive with public API. @@ -53,6 +54,10 @@ export class TestingBehatRuntimeService { return CorePushNotifications.instance; } + get sites(): CoreSitesProvider { + return CoreSites.instance; + } + /** * Init behat functions and set options like skipping onboarding. * diff --git a/src/tests/behat/navigation_deeplinks.feature b/src/tests/behat/navigation_deeplinks.feature index 4394a477f..9c963164e 100644 --- a/src/tests/behat/navigation_deeplinks.feature +++ b/src/tests/behat/navigation_deeplinks.feature @@ -25,9 +25,7 @@ Feature: It navigates properly using deep links. Scenario: Receive a push notification Given I entered the app as "student2" - When I press the user menu button in the app - And I press "Log out" in the app - And I wait the app to restart + When I log out in the app And I press "Add" in the app And I set the field "Your site" to "$WWWROOT" in the app And I press "Connect to your site" in the app @@ -67,9 +65,7 @@ Feature: It navigates properly using deep links. Scenario: Open a link with a custom URL that calls WebServices for a logged out site Given I entered the app as "student2" - When I press the user menu button in the app - And I press "Log out" in the app - And I wait the app to restart + When I log out in the app And I open a custom link in the app for: | forum | | Test forum |