/** * Wait for JS to complete after finishing the step. * * With this we ensure that there are not AJAX calls * still in progress. * * Executed only when running against a real browser. We wrap it * all in a try & catch to forward the exception to i_look_for_exceptions * so the exception will be at scenario level, which causes a failure, by * default would be at framework level, which will stop the execution of * the run. * * @param AfterStepScope $scope scope passed by event fired after step.. * @AfterStep */ public function after_step_javascript(AfterStepScope $scope) { global $CFG, $DB; // Save the page content if the step failed. if (!empty($CFG->behat_faildump_path) && $scope->getTestResult()->getResultCode() === Behat\Testwork\Tester\Result\TestResult::FAILED) { $this->take_contentdump($scope); } // Abort any open transactions to prevent subsequent tests hanging. // This does the same as abort_all_db_transactions(), but doesn't call error_log() as we don't // want to see a message in the behat output. if ($scope->getTestResult() instanceof \Behat\Behat\Tester\Result\ExecutedStepResult && $scope->getTestResult()->hasException()) { if ($DB && $DB->is_transaction_started()) { $DB->force_transaction_rollback(); } } // Only run if JS. if (!$this->running_javascript()) { return; } // Save a screenshot if the step failed. if (!empty($CFG->behat_faildump_path) && $scope->getTestResult()->getResultCode() === Behat\Testwork\Tester\Result\TestResult::FAILED) { $this->take_screenshot($scope); } try { $this->wait_for_pending_js(); self::$currentstepexception = null; } catch (UnexpectedAlertOpen $e) { self::$currentstepexception = $e; // Accepting the alert so the framework can continue properly running // the following scenarios. Some browsers already closes the alert, so // wrapping in a try & catch. try { $this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); } catch (Exception $e) { // Catching the generic one as we never know how drivers reacts here. } } catch (Exception $e) { self::$currentstepexception = $e; } }
/** * Wait for JS to complete after finishing the step. * * With this we ensure that there are not AJAX calls * still in progress. * * Executed only when running against a real browser. We wrap it * all in a try & catch to forward the exception to i_look_for_exceptions * so the exception will be at scenario level, which causes a failure, by * default would be at framework level, which will stop the execution of * the run. * * @AfterStep @javascript */ public function after_step_javascript($event) { global $CFG; // Save a screenshot if the step failed. if (!empty($CFG->behat_faildump_path) && $event->getResult() === StepEvent::FAILED) { $this->take_screenshot($event); } try { $this->wait_for_pending_js(); self::$currentstepexception = null; } catch (UnexpectedAlertOpen $e) { self::$currentstepexception = $e; // Accepting the alert so the framework can continue properly running // the following scenarios. Some browsers already closes the alert, so // wrapping in a try & catch. try { $this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); } catch (Exception $e) { // Catching the generic one as we never know how drivers reacts here. } } catch (Exception $e) { self::$currentstepexception = $e; } }