/** * @param ScenarioEvent|OutlineExampleEvent $event * @return void */ public function after($event) { $ctx = $event->getContext(); if ($ctx instanceof BehatContext) { $ctx->tearDown(); } }
/** * Listens to "outline.example.after" event. * * @param OutlineExampleEvent $event */ public function afterOutlineExample(OutlineExampleEvent $event) { $outline = $event->getOutline(); $examples = $outline->getExamples(); $lines = $examples->getRowLines(); $this->writeln($outline->getFile() . ':' . $lines[$event->getIteration() + 1]); }
/** * {@inheritDoc} */ public function afterOutlineExample(OutlineExampleEvent $event) { $context = $event->getContext(); if ($context instanceof SauceContext) { if (!$context->isLocal()) { $this->sauce_link = $context->getNoLoginJobLink(); } } parent::afterOutlineExample($event); $this->sauce_link = null; }
/** * Return recorded events * * @return array */ public function getEvents() { $events = $this->getEventRecorder()->rip(); foreach ($events as $key => $eventTurple) { list($name, $event) = $eventTurple; if ($event instanceof StepEvent) { $event = new StepEvent($event->getStep(), $event->getLogicalParent(), new NullContext(), $event->getResult(), null, $event->getException() ? new WorkerException($event->getException()->getMessage()) : null, $event->getSnippet()); } if ($event instanceof OutlineExampleEvent) { $event = new OutlineExampleEvent($event->getOutline(), $event->getIteration(), new NullContext(), $event->getResult(), $event->isSkipped()); } if ($event instanceof ScenarioEvent) { $event = new ScenarioEvent($event->getScenario(), new NullContext(), $event->getResult(), $event->isSkipped()); } $event->setDispatcher(new NullEventDispatcher()); $events[$key] = array($name, $event); } return $events; }
/** * Listens to "outline.example.after" event. * * @param OutlineExampleEvent $event * * @uses printOutlineExampleFooter() */ public function afterOutlineExample(OutlineExampleEvent $event) { $this->inOutlineExample = false; $this->printOutlineExampleFooter($event->getOutline(), $event->getIteration(), $event->getResult(), $event->isSkipped()); }
/** * Resets the test environment. * * @param OutlineExampleEvent|ScenarioEvent $event event fired before scenario. * @throws coding_exception If here we are not using the test database it should be because of a coding error * @BeforeScenario */ public function before_scenario($event) { global $DB, $SESSION, $CFG; // As many checks as we can. if (!defined('BEHAT_TEST') || !defined('BEHAT_SITE_RUNNING') || php_sapi_name() != 'cli' || !behat_util::is_test_mode_enabled() || !behat_util::is_test_site()) { throw new coding_exception('Behat only can modify the test database and the test dataroot!'); } $moreinfo = 'More info in ' . behat_command::DOCS_URL . '#Running_tests'; $driverexceptionmsg = 'Selenium server is not running, you need to start it to run tests that involve Javascript. ' . $moreinfo; try { $session = $this->getSession(); } catch (CurlExec $e) { // Exception thrown by WebDriver, so only @javascript tests will be caugth; in // behat_util::is_server_running() we already checked that the server is running. throw new Exception($driverexceptionmsg); } catch (DriverException $e) { throw new Exception($driverexceptionmsg); } catch (UnknownError $e) { // Generic 'I have no idea' Selenium error. Custom exception to provide more feedback about possible solutions. $this->throw_unknown_exception($e); } // We need the Mink session to do it and we do it only before the first scenario. if (self::is_first_scenario()) { behat_selectors::register_moodle_selectors($session); behat_context_helper::set_main_context($event->getContext()->getMainContext()); } // Reset mink session between the scenarios. $session->reset(); // Reset $SESSION. \core\session\manager::init_empty_session(); behat_util::reset_all_data(); // Assign valid data to admin user (some generator-related code needs a valid user). $user = $DB->get_record('user', array('username' => 'admin')); \core\session\manager::set_user($user); // Reset the browser if specified in config.php. if (!empty($CFG->behat_restart_browser_after) && $this->running_javascript()) { $now = time(); if (self::$lastbrowsersessionstart + $CFG->behat_restart_browser_after < $now) { $session->restart(); self::$lastbrowsersessionstart = $now; } } // Start always in the the homepage. try { // Let's be conservative as we never know when new upstream issues will affect us. $session->visit($this->locate_path('/')); } catch (UnknownError $e) { $this->throw_unknown_exception($e); } // Checking that the root path is a Moodle test site. if (self::is_first_scenario()) { $notestsiteexception = new Exception('The base URL (' . $CFG->wwwroot . ') is not a behat test site, ' . 'ensure you started the built-in web server in the correct directory or your web server is correctly started and set up'); $this->find("xpath", "//head/child::title[normalize-space(.)='" . behat_util::BEHATSITENAME . "']", $notestsiteexception); self::$initprocessesfinished = true; } // Run all test with medium (1024x768) screen size, to avoid responsive problems. $this->resize_window('medium'); }
/** * Listens to "outline.example.after" event. * * @param Behat\Behat\Event\OutlineExampleEvent $event * * @uses collectScenarioResult() */ public function afterOutlineExample(OutlineExampleEvent $event) { $this->collectScenarioResult($event->getResult()); }
/** * @param ScenarioEvent|OutlineExampleEvent $event */ public function afterScenario($event) { if (!$this->enabled) { return; } $this->currentReport['result'] = $event->getResult(); $this->report[] = $this->currentReport; }