MOBILE-3320 behat: Implement step to wait restart
parent
6d1b7c52ed
commit
561206b785
|
@ -100,6 +100,19 @@ class behat_app extends behat_base {
|
||||||
$this->prepare_browser();
|
$this->prepare_browser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Then /^I wait the app to restart$/
|
||||||
|
*/
|
||||||
|
public function i_wait_the_app_to_restart() {
|
||||||
|
// Wait window to reload.
|
||||||
|
$this->spin(function() {
|
||||||
|
return $this->evaluate_script("return !window.behat;");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Prepare testing runtime again.
|
||||||
|
$this->prepare_browser(false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds elements in the app.
|
* Finds elements in the app.
|
||||||
*
|
*
|
||||||
|
@ -347,7 +360,8 @@ class behat_app extends behat_base {
|
||||||
* @param string $url App URL
|
* @param string $url App URL
|
||||||
* @throws DriverException If the app fails to load properly
|
* @throws DriverException If the app fails to load properly
|
||||||
*/
|
*/
|
||||||
protected function prepare_browser() {
|
protected function prepare_browser(bool $restart = true) {
|
||||||
|
if ($restart) {
|
||||||
// Restart the browser and set its size.
|
// Restart the browser and set its size.
|
||||||
$this->getSession()->restart();
|
$this->getSession()->restart();
|
||||||
$this->resize_window('360x720', true);
|
$this->resize_window('360x720', true);
|
||||||
|
@ -363,8 +377,11 @@ class behat_app extends behat_base {
|
||||||
|
|
||||||
$this->islegacy = version_compare($appversion, '3.9.5', '<');
|
$this->islegacy = version_compare($appversion, '3.9.5', '<');
|
||||||
|
|
||||||
// Visit the Ionic URL and wait for it to load.
|
// Visit the Ionic URL.
|
||||||
$this->getSession()->visit($this->ionicurl);
|
$this->getSession()->visit($this->ionicurl);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait the application to load.
|
||||||
$this->spin(function($context) {
|
$this->spin(function($context) {
|
||||||
$title = $context->getSession()->getPage()->find('xpath', '//title');
|
$title = $context->getSession()->getPage()->find('xpath', '//title');
|
||||||
|
|
||||||
|
@ -387,6 +404,7 @@ class behat_app extends behat_base {
|
||||||
$this->execute_script("window.BehatMoodleAppLegacy = $islegacyboolean;");
|
$this->execute_script("window.BehatMoodleAppLegacy = $islegacyboolean;");
|
||||||
$this->execute_script(file_get_contents(__DIR__ . '/app_behat_runtime.js'));
|
$this->execute_script(file_get_contents(__DIR__ . '/app_behat_runtime.js'));
|
||||||
|
|
||||||
|
if ($restart) {
|
||||||
// Assert initial page.
|
// Assert initial page.
|
||||||
$this->spin(function($context) {
|
$this->spin(function($context) {
|
||||||
$page = $context->getSession()->getPage();
|
$page = $context->getSession()->getPage();
|
||||||
|
@ -415,6 +433,7 @@ class behat_app extends behat_base {
|
||||||
|
|
||||||
throw new DriverException('Moodle app not launched properly');
|
throw new DriverException('Moodle app not launched properly');
|
||||||
}, false, 60);
|
}, false, 60);
|
||||||
|
}
|
||||||
|
|
||||||
// Continue only after JS finishes.
|
// Continue only after JS finishes.
|
||||||
$this->wait_for_pending_js();
|
$this->wait_for_pending_js();
|
||||||
|
|
Loading…
Reference in New Issue