From a3481d6f9b0650177de93ca19a4828fc2ee8befd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 7 Jul 2022 14:37:57 +0200 Subject: [PATCH] MOBILE-4047 behat: Fix restart on change user --- .../tests/behat/behat_app.php | 17 ++++---------- .../tests/behat/behat_app_helper.php | 23 +++++++++++-------- .../login/tests/behat/basic_usage.feature | 3 +-- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/local_moodleappbehat/tests/behat/behat_app.php b/local_moodleappbehat/tests/behat/behat_app.php index 1ce830d2a..3ddc2b583 100644 --- a/local_moodleappbehat/tests/behat/behat_app.php +++ b/local_moodleappbehat/tests/behat/behat_app.php @@ -91,8 +91,6 @@ class behat_app extends behat_app_helper { * @throws ExpectationException Problem with resizing window */ public function i_launch_the_app(string $runtime = '') { - $this->check_tags(); - // Go to page and prepare browser for app. $this->prepare_browser(['skiponboarding' => empty($runtime)]); } @@ -101,18 +99,13 @@ class behat_app extends behat_app_helper { * @Then I wait the app to restart */ public function i_wait_the_app_to_restart() { - // Wait window to reload. - $this->spin(function() { - if ($this->runtime_js('hasInitialized()')) { - // Behat runtime shouldn't be initialized after reload. - throw new DriverException('Window is not reloading properly.'); - } - - return true; - }); + if ($this->runtime_js('hasInitialized()')) { + // Already initialized. + return; + } // Prepare testing runtime again. - $this->prepare_browser(['restart' => false]); + $this->prepare_browser(); } /** diff --git a/local_moodleappbehat/tests/behat/behat_app_helper.php b/local_moodleappbehat/tests/behat/behat_app_helper.php index 9f8236183..41f9972f2 100644 --- a/local_moodleappbehat/tests/behat/behat_app_helper.php +++ b/local_moodleappbehat/tests/behat/behat_app_helper.php @@ -95,6 +95,12 @@ class behat_app_helper extends behat_base { public function start_scenario() { $this->check_behat_setup(); $this->fix_moodle_setup(); + + if ($this->apprunning) { + $this->notify_unload(); + $this->apprunning = false; + } + $this->ionicurl = $this->start_or_reuse_ionic(); } @@ -274,17 +280,15 @@ class behat_app_helper extends behat_base { * @throws DriverException If the app fails to load properly */ protected function prepare_browser(array $options = []) { - $restart = $options['restart'] ?? true; + $restart = false; - if ($restart) { - if ($this->apprunning) { - $this->notify_unload(); - } + if (!$this->apprunning) { + $this->check_tags(); - // Restart the browser and set its size. - $this->getSession()->restart(); + $restart = true; + + // Reset its size. $this->resize_window($this->windowsize, true); - if (empty($this->ionicurl)) { $this->ionicurl = $this->start_or_reuse_ionic(); } @@ -536,7 +540,6 @@ class behat_app_helper extends behat_base { if ($result !== 'OK') { throw new DriverException('Error handling url - ' . $result); } - if (!empty($successXPath)) { // Wait until the page appears. $this->spin( @@ -550,6 +553,8 @@ class behat_app_helper extends behat_base { } $this->wait_for_pending_js(); + + $this->i_wait_the_app_to_restart(); } /** diff --git a/src/core/features/login/tests/behat/basic_usage.feature b/src/core/features/login/tests/behat/basic_usage.feature index d03a08844..136ef3f1d 100755 --- a/src/core/features/login/tests/behat/basic_usage.feature +++ b/src/core/features/login/tests/behat/basic_usage.feature @@ -26,8 +26,7 @@ Feature: Test basic usage of login in app And I should find "Connect to Moodle" in the app Scenario: Add a new account in the app & Site name in displayed when adding a new account - When I enter the app - And I press the back button in the app + When I launch the app And I set the field "Your site" to "$WWWROOT" in the app And I press "Connect to your site" in the app Then I should find "Acceptance test site" in the app