. /** * Behat step definitions. * * @package local_apps * @copyright 2010 Moodle Pty Ltd (http://moodle.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ use Behat\Mink\Exception\ExpectationException; // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); /** * Behat step definitions. * * @package local_apps * @copyright 2010 Moodle Pty Ltd (http://moodle.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class behat_local_moodlemobileapp extends behat_base { /** * Force cron tasks instead of waiting for the next scheduled execution. * * @When /^I run cron tasks in the app$/ */ public function i_run_cron_tasks_in_the_app() { $session = $this->getSession(); // Force cron tasks execution and wait until they are completed. $operationid = random_string(); $session->executeScript( "cronProvider.forceSyncExecution().then(() => { window['behat_{$operationid}_completed'] = true; });" ); $this->spin( function() use ($session, $operationid) { return $session->evaluateScript("window['behat_{$operationid}_completed'] || false"); }, false, 60, new ExpectationException('Forced cron tasks in the app took too long to complete', $session) ); // Trigger Angular digest cycle multiple times in case some changes have // side-effects that result in further pending operations. for ($ticks = 5; $ticks > 0; $ticks--) { $session->executeScript('appRef.tick();'); } } /** * Wait until loading has finished. * * @When /^I wait loading to finish in the app$/ */ public function i_wait_loading_to_finish_in_the_app() { $session = $this->getSession(); $this->spin( function() use ($session) { $session->executeScript('appRef.tick();'); $nodes = $this->find_all('css', 'core-loading ion-spinner'); foreach ($nodes as $node) { if (!$node->isVisible()) { continue; } return false; } return true; }, false, 60, new ExpectationException('"Loading took too long to complete', $session) ); } /** * Replaces $WWWROOT for the url of the Moodle site. * * @Transform /^(.*\$WWWROOT.*)$/ * @param string $text Text. * @return string */ public function arg_replace_wwwroot($text) { global $CFG; return str_replace('$WWWROOT', $CFG->behat_wwwroot, $text); } }