/** * 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(BeforeScenario $event) { global $DB, $CFG; // TODO: check config value to ensure site is set for performance data. $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_session($session); // Ensure performance site is enable. if (!get_config('core', 'performancesitedata')) { $notperformancesite = "This is not a performance site" . PHP_EOL . " - Run vendor/bin/moodle_behat_2jmx --enable=s" . PHP_EOL; throw new Exception($notperformancesite); } } // Start a new thread group. testplan_writer::start_thread_group(self::$featurefile, self::$threadgroupname); }