MOBILE-4047 behat: Fix restart on change user

main
Pau Ferrer Ocaña 2022-07-07 14:37:57 +02:00
parent 29d97cca3a
commit a3481d6f9b
3 changed files with 20 additions and 23 deletions

View File

@ -91,8 +91,6 @@ class behat_app extends behat_app_helper {
* @throws ExpectationException Problem with resizing window * @throws ExpectationException Problem with resizing window
*/ */
public function i_launch_the_app(string $runtime = '') { public function i_launch_the_app(string $runtime = '') {
$this->check_tags();
// Go to page and prepare browser for app. // Go to page and prepare browser for app.
$this->prepare_browser(['skiponboarding' => empty($runtime)]); $this->prepare_browser(['skiponboarding' => empty($runtime)]);
} }
@ -101,18 +99,13 @@ class behat_app extends behat_app_helper {
* @Then I wait the app to restart * @Then I wait the app to restart
*/ */
public function i_wait_the_app_to_restart() { public function i_wait_the_app_to_restart() {
// Wait window to reload. if ($this->runtime_js('hasInitialized()')) {
$this->spin(function() { // Already initialized.
if ($this->runtime_js('hasInitialized()')) { return;
// Behat runtime shouldn't be initialized after reload. }
throw new DriverException('Window is not reloading properly.');
}
return true;
});
// Prepare testing runtime again. // Prepare testing runtime again.
$this->prepare_browser(['restart' => false]); $this->prepare_browser();
} }
/** /**

View File

@ -95,6 +95,12 @@ class behat_app_helper extends behat_base {
public function start_scenario() { public function start_scenario() {
$this->check_behat_setup(); $this->check_behat_setup();
$this->fix_moodle_setup(); $this->fix_moodle_setup();
if ($this->apprunning) {
$this->notify_unload();
$this->apprunning = false;
}
$this->ionicurl = $this->start_or_reuse_ionic(); $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 * @throws DriverException If the app fails to load properly
*/ */
protected function prepare_browser(array $options = []) { protected function prepare_browser(array $options = []) {
$restart = $options['restart'] ?? true; $restart = false;
if ($restart) { if (!$this->apprunning) {
if ($this->apprunning) { $this->check_tags();
$this->notify_unload();
}
// Restart the browser and set its size. $restart = true;
$this->getSession()->restart();
// Reset its size.
$this->resize_window($this->windowsize, true); $this->resize_window($this->windowsize, true);
if (empty($this->ionicurl)) { if (empty($this->ionicurl)) {
$this->ionicurl = $this->start_or_reuse_ionic(); $this->ionicurl = $this->start_or_reuse_ionic();
} }
@ -536,7 +540,6 @@ class behat_app_helper extends behat_base {
if ($result !== 'OK') { if ($result !== 'OK') {
throw new DriverException('Error handling url - ' . $result); throw new DriverException('Error handling url - ' . $result);
} }
if (!empty($successXPath)) { if (!empty($successXPath)) {
// Wait until the page appears. // Wait until the page appears.
$this->spin( $this->spin(
@ -550,6 +553,8 @@ class behat_app_helper extends behat_base {
} }
$this->wait_for_pending_js(); $this->wait_for_pending_js();
$this->i_wait_the_app_to_restart();
} }
/** /**

View File

@ -26,8 +26,7 @@ Feature: Test basic usage of login in app
And I should find "Connect to Moodle" in the 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 Scenario: Add a new account in the app & Site name in displayed when adding a new account
When I enter the app When I launch the app
And I press the back button in the app
And I set the field "Your site" to "$WWWROOT" 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 And I press "Connect to your site" in the app
Then I should find "Acceptance test site" in the app Then I should find "Acceptance test site" in the app