Exemplo n.º 1
0
 /**
  * @param ScenarioEvent|OutlineExampleEvent $event
  * @return void
  */
 public function after($event)
 {
     $ctx = $event->getContext();
     if ($ctx instanceof BehatContext) {
         $ctx->tearDown();
     }
 }
Exemplo n.º 2
0
 /**
  * Listens to "scenario.after" event.
  *
  * @param   Behat\Behat\Event\ScenarioEvent     $event
  */
 public function afterScenario(ScenarioEvent $event)
 {
     if (StepEvent::FAILED === $event->getResult()) {
         $scenario = $event->getScenario();
         $this->writeln($scenario->getFile() . ':' . $scenario->getLine());
     }
 }
 function let(CodeCoverageSession $coverageSession, Session $session, Filesystem $filesystem, StepEvent $stepEvent, StepNode $stepNode, ScenarioEvent $scenarioEvent, ScenarioNode $scenarioNode)
 {
     $stepEvent->getStep()->willReturn($stepNode);
     $stepEvent->getResult()->willReturn(StepEvent::PASSED);
     $scenarioEvent->getScenario()->willReturn($scenarioNode);
     $scenarioEvent->getResult()->willReturn(StepEvent::PASSED);
     $this->beConstructedWith($coverageSession, $session, $filesystem);
 }
Exemplo n.º 4
0
 /**
  * After Scenario hook
  *
  * @param ScenarioEvent $event
  */
 public function afterScenario(ScenarioEvent $event)
 {
     $scenario = $event->getScenario();
     $feature = $scenario->getFeature();
     $url = $feature->getFile();
     $issue = $this->jiraService->getIssue($url);
     if ($issue) {
         $this->postComment($issue, $event->getResult(), $scenario->getTitle());
         $this->updateIssue($issue, $event->getResult());
     }
 }
Exemplo n.º 5
0
 /**
  * {@inheritDoc}
  */
 public function beforeScenario(ScenarioEvent $event)
 {
     $context = $event->getContext();
     if ($context instanceof SauceContext) {
         if (!$context->isLocal()) {
             $this->sauce_link = $context->getNoLoginJobLink();
         }
     }
     parent::beforeScenario($event);
     $this->sauce_link = null;
 }
Exemplo n.º 6
0
 /**
  * @AfterScenario
  */
 public function printLastResponseOnError(ScenarioEvent $scenarioEvent)
 {
     if ($scenarioEvent->getResult() != 0) {
         // avoid the error if we're using Goutte and there has been no request yet
         if ($this->getSession()->getDriver() instanceof GoutteDriver && !$this->getSession()->getDriver()->getClient()->getRequest()) {
             return;
         }
         // uncomment to better scenario debug
         //$this->getSubcontext('mink')->printLastResponse();
     }
 }
 /**
  * @AfterScenario
  */
 public function tearDown(ScenarioEvent $event)
 {
     if (empty($this->parameters['instances'])) {
         return;
         // Local Setup doesn't need to transmit data to testingbot
     }
     $url = $this->getSession()->getCurrentUrl();
     $parts = explode("/", $url);
     $sessionID = $parts[sizeof($parts) - 1];
     $data = array('session_id' => $sessionID, 'client_key' => $this->parameters['key'], 'client_secret' => $this->parameters['secret'], 'success' => $event->getResult() === 0 ? true : false, 'name' => $event->getScenario()->getTitle());
     $this->apiCall($data);
 }
Exemplo n.º 8
0
 /**
  * @BeforeScenario
  */
 public function beforeScenario(ScenarioEvent $event)
 {
     if (in_array('javascript', $event->getScenario()->getTags())) {
         $client = new Client();
         $client->request('GET', $this->getUrl('test/reinstall'));
         $status = $client->getResponse()->getStatus();
         $content = $client->getResponse()->getContent();
     } else {
         $this->visit('test/reinstall');
         $status = $this->getSession()->getStatusCode();
         $content = $this->getSession()->getPage()->getContent();
     }
     $this->checkForResponseError($status, $content, 'Unable to init platform');
 }
Exemplo n.º 9
0
 /**
  * @AfterScenario
  */
 public static function cleanDB(ScenarioEvent $event)
 {
     $parameters = $event->getContext()->parameters;
     if (empty($parameters['config_file']) || !is_readable($parameters['config_file'])) {
         throw new Exception(sprintf('Config file %s does not exist or not readable', $parameters['config_file']));
     }
     self::getConnection($parameters);
     if (empty($parameters['sql_cleanup_file']) && !is_readable($parameters['sql_cleanup_file'])) {
         throw new Exception(sprintf('sql cleanup file %s does not exist or not readable', $parameters['sql_cleanup_file']));
     }
     if (!empty($parameters['user_id_to_not_delete'])) {
         $replace_user_id = $parameters['user_id_to_not_delete'];
     } else {
         $replace_user_id = null;
     }
     self::executeSqlFile($parameters['sql_cleanup_file'], $replace_user_id);
 }
Exemplo n.º 10
0
 public function after(ScenarioEvent $event)
 {
     if ($event->getResult() !== StepEvent::FAILED || !defined('TEMP_DIR')) {
         return;
     }
     echo "\nDumping error logs... \n";
     foreach (array_merge(glob(TEMP_DIR . '/error.log'), glob(TEMP_DIR . '/info.log'), glob(TEMP_DIR . '/critical.log')) as $logfile) {
         readfile($logfile);
         echo "\n";
     }
     if (!Debugger::$browser) {
         return;
     }
     echo "\nOpening bluescreens... \n";
     foreach (glob(TEMP_DIR . '/exception-*.html') as $file) {
         exec(Debugger::$browser . ' ' . escapeshellarg($file));
     }
 }
Exemplo n.º 11
0
 /**
  * Configures default Mink session before each scenario.
  * Configuration is based on provided scenario tags:
  *
  * `@javascript` tagged scenarios will get `javascript_session` as default session
  * `@mink:CUSTOM_NAME tagged scenarios will get `CUSTOM_NAME` as default session
  * Other scenarios get `default_session` as default session
  *
  * `@insulated` tag will cause Mink to stop current sessions before scenario
  * instead of just soft-resetting them
  *
  * @param ScenarioEvent|OutlineExampleEvent $event
  */
 public function prepareDefaultMinkSession($event)
 {
     $scenario = $event instanceof ScenarioEvent ? $event->getScenario() : $event->getOutline();
     $session = $this->parameters['default_session'];
     foreach ($scenario->getTags() as $tag) {
         if ('javascript' === $tag) {
             $session = $this->parameters['javascript_session'];
         } elseif (preg_match('/^mink\\:(.+)/', $tag, $matches)) {
             $session = $matches[1];
         }
     }
     if ($scenario->hasTag('insulated')) {
         $this->mink->stopSessions();
     } else {
         $this->mink->resetSessions();
     }
     $this->mink->setDefaultSessionName($session);
 }
Exemplo n.º 12
0
 /**
  * @AfterScenario
  * @param ScenarioEvent $event
  */
 public function stopCapture(ScenarioEvent $event)
 {
     if ($this->captureProcess !== NULL) {
         $tmpFilePath = $this->getTmpFilename();
         $failedCapturePath = rtrim($this->reportsPath, '/') . '/' . strtr($event->getScenario()->getTitle(), array(' ' => '_', '.' => '_')) . '.mp4';
         $this->captureProcess->stop(3, SIGTERM);
         if (file_exists($tmpFilePath)) {
             if ($event->getResult() === StepEvent::FAILED) {
                 if (!is_dir(dirname($failedCapturePath))) {
                     mkdir(dirname($failedCapturePath), 0777, TRUE);
                 }
                 if (file_exists($failedCapturePath)) {
                     unlink($failedCapturePath);
                 }
                 rename($tmpFilePath, $failedCapturePath);
             } else {
                 unlink($tmpFilePath);
             }
         }
     }
     $this->captureProcess = NULL;
 }
Exemplo n.º 13
0
 private function buildScenarioEvent(ScenarioEvent $event)
 {
     $node = $event->getScenario();
     $message = "  Scenario: " . $node->getTitle() . ' line: ' . $node->getLine();
     $this->file = $node->getFile();
     $this->line = $node->getLine();
     $this->text = $node->getTitle();
     $this->node = $node;
     return $message;
 }
 /**
  * Listens to "scenario.after" event.
  *
  * @param ScenarioEvent $event
  */
 public function afterScenario(ScenarioEvent $event)
 {
     $scenario = $event->getScenario();
     $this->writeln($scenario->getFile() . ':' . $scenario->getLine());
 }
 /**
  * Close modal dialog if test scenario fails on CMS page
  *
  * @AfterScenario
  */
 public function closeModalDialog(ScenarioEvent $event)
 {
     try {
         // Only for failed tests on CMS page
         if (4 === $event->getResult()) {
             $cmsElement = $this->getSession()->getPage()->find('css', '.cms');
             if ($cmsElement) {
                 try {
                     // Navigate away triggered by reloading the page
                     $this->getSession()->reload();
                     $this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
                 } catch (\WebDriver\Exception $e) {
                     // no-op, alert might not be present
                 }
             }
         }
     } catch (\WebDriver\Exception $e) {
         $this->logException($e);
     }
 }
Exemplo n.º 16
0
 /**
  * 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;
 }
Exemplo n.º 17
0
 /**
  * @AfterScenario
  */
 public static function cleanDB(ScenarioEvent $event)
 {
     $parameters = $event->getContext()->parameters;
     if (empty($parameters['config_file']) || !is_readable($parameters['config_file'])) {
         throw new \Exception(sprintf('Config file %s does not exist or not readable', $parameters['config_file']));
     }
     if (empty($parameters['sql_cleanup_file']) && !is_readable($parameters['sql_cleanup_file'])) {
         throw new \Exception(sprintf('sql cleanup file %s does not exist or not readable', $parameters['sql_cleanup_file']));
     }
     self::getConfigDb($parameters)->readSqlFile($parameters['sql_cleanup_file']);
 }
Exemplo n.º 18
0
 function let(ScenarioEvent $event, ScenarioNode $node)
 {
     $event->getScenario()->willReturn($node);
     $this->beConstructedWith($event);
 }
Exemplo n.º 19
0
 /**
  * Listens to "scenario.after" event.
  *
  * @param ScenarioEvent $event
  *
  * @uses printScenarioFooter()
  */
 public function afterScenario(ScenarioEvent $event)
 {
     $this->printScenarioFooter($event->getScenario());
 }
Exemplo n.º 20
0
 /**
  * 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');
 }
Exemplo n.º 21
0
 /**
  * Configures default Drupal driver to use before each scenario or outline.
  *
  * `@api` tagged scenarios will get the `api_driver` as the default driver.
  *
  * Other scenarios get the `default_driver` as the default driver.
  *
  * @param ScenarioEvent|OutlineEvent $event
  */
 public function prepareDefaultDrupalDriver($event)
 {
     $scenario = $event instanceof ScenarioEvent ? $event->getScenario() : $event->getOutline();
     // Set the default driver.
     $driver = $this->parameters['default_driver'];
     foreach ($scenario->getTags() as $tag) {
         if (isset($this->parameters[$tag . '_driver'])) {
             $driver = $this->parameters[$tag . '_driver'];
         }
     }
     $this->drupal->setDefaultDriverName($driver);
 }
Exemplo n.º 22
0
 /**
  * Listens to "scenario.after" event.
  *
  * @param   Behat\Behat\Event\ScenarioEvent $event
  *
  * @uses    collectScenarioResult()
  */
 public function afterScenario(ScenarioEvent $event)
 {
     $this->collectScenarioResult($event->getResult());
 }
 /**
  * Listens to "scenario.before" event.
  *
  * @param ScenarioEvent $event Event that contains the scenario.
  */
 public function beforeScenario(ScenarioEvent $event)
 {
     $this->_client->startScenario($event->getScenario()->getTitle());
 }
 /**
  * Listens to "scenario.before" event.
  *
  * @param ScenarioEvent $event
  *
  * @uses printScenarioHeader()
  */
 public function beforeScenario(ScenarioEvent $event)
 {
     $scenario = $event->getScenario();
     $this->currentScenario = $this->createScenario($scenario, 'scenario');
 }
 /**
  * Keep track of the current scenario and step number for use in the file name
  *
  * @param ScenarioEvent $event
  */
 public function resetStepCounter(ScenarioEvent $event)
 {
     $this->currentScenario = $event->getScenario();
     $this->stepNumber = 0;
 }
Exemplo n.º 26
0
 /**
  * @param ScenarioEvent|OutlineExampleEvent $event
  */
 public function afterScenario($event)
 {
     if (!$this->enabled) {
         return;
     }
     $this->currentReport['result'] = $event->getResult();
     $this->report[] = $this->currentReport;
 }