/**
  * Automated Screenshot on fail
  *
  *
  * @AfterStep
  */
 public function afterStep(Behat\Behat\Event\StepEvent $event)
 {
     $context = $event->getContext();
     if ($context->getMinkParameter('browser_name') == 'phantomjs' && $event->getResult() == StepEvent::FAILED) {
         $this->iTakeAScreenshotWithName('fail');
     }
 }
 /**
  * After state hook to write failure back to the page, which alerts phantom to a 
  * failure. See: http://shaneauckland.co.uk/2012/11/capturing-screenshots-with-mink-sahi-and-phantomjs/
  * 
  * @AfterStep
  */
 public function afterStep(StepEvent $event)
 {
     $context = $event->getContext();
     if ($context->getMinkParameter('browser_name') == 'phantomjs' && $event->getResult() == StepEvent::FAILED) {
         $javascript = 'window.callPhantom({value:"fail"})';
         $context->getSession()->executeScript($javascript);
     }
 }
Exemple #3
0
 /** @AfterStep */
 public function afterStep(StepEvent $event)
 {
     /**
      * @var $context \Behat\MinkExtension\Context\MinkContext
      */
     $context = $event->getContext();
     if ($this->parameters['screenshots']['enabled'] && $context->getMinkParameter('browser_name') == 'phantomjs' && $event->getResult() == StepEvent::FAILED) {
         $string = str_replace("'", "_", $event->getStep()->getLine() . ":" . $event->getStep()->getText());
         $context->getSession()->executeScript('window.callPhantom(\'' . $string . '\')');
         //TODO: show output via console; toggle output
         print "Wrote screenshot to {$string}\n";
     }
 }
 /**
  * Searches and runs provided step delegating all the process to the parent class
  *
  * Method overwritten to look for:
  * - Moodle exceptions
  * - Moodle debugging() calls
  * - PHP debug messages (depends on the PHP debug level)
  *
  * @param StepNode $step step node
  * @return StepEvent
  */
 protected function executeStep(StepNode $step)
 {
     // Redirect to the parent to run the step.
     $afterEvent = parent::executeStep($step);
     // Catch Moodle Behat skip exception.
     if ($afterEvent->getException() instanceof SkippedException) {
         return new StepEvent($afterEvent->getStep(), $afterEvent->getLogicalParent(), $afterEvent->getContext(), StepEvent::SKIPPED, $afterEvent->getDefinition(), $afterEvent->getException(), null);
     }
     // We set $this->dispatchafterstep to true when a step is in the lower level
     // but if a step is throwing an exception it doesn't arrive to the point where
     // we set dispatchafterstep to true and the event is not dispatched; here we
     // set it but we also check failredstep so the parent steps (in a chain) don't
     // continue dispatching the event.
     if ($afterEvent->getResult() !== StepEvent::PASSED && $this->failedstep === false) {
         $this->dispatchafterstep = true;
     }
     // Extra step, looking for a moodle exception, a debugging() message or a PHP debug message.
     $checkingStep = new StepNode('Then', self::EXCEPTIONS_STEP_TEXT, $step->getLine());
     $afterExceptionCheckingEvent = parent::executeStep($checkingStep);
     // If it find something wrong we overwrite the original step result.
     if ($afterExceptionCheckingEvent->getResult() == StepEvent::FAILED) {
         // Creating a mix of both StepEvents to report about it as a failure in the original step.
         $afterEvent = new StepEvent($afterEvent->getStep(), $afterEvent->getLogicalParent(), $afterEvent->getContext(), $afterExceptionCheckingEvent->getResult(), $afterEvent->getDefinition(), $afterExceptionCheckingEvent->getException(), null);
     }
     return $afterEvent;
 }
Exemple #5
0
 public function afterStep(StepEvent $event)
 {
     if (!$this->enabled) {
         return;
     }
     if (in_array($event->getResult(), $this->ignoredStates)) {
         return;
     }
     // screenshot not needed for these states
     $file = $event->getStep()->getParent()->getFeature()->getFile();
     $line = $event->getStep()->getLine();
     $filename = str_replace('/', '_', ltrim(str_replace($this->rootDir, '', $file), '/')) . '_' . $line . '.png';
     /** @var BehatContext $ctx */
     $ctx = $event->getContext();
     $screenData = $ctx->getSession()->currentScreenshot();
     file_put_contents($this->outDir . '/' . $filename, $screenData);
     $this->currentReport['steps'][] = array('text' => $event->getStep()->getText(), 'file' => $filename, 'result' => $event->getResult(), 'exception' => ($ex = $event->getException()) ? $ex->getMessage() : NULL);
 }
 public function afterStep(StepEvent $event)
 {
     if (!$this->valid()) {
         return false;
     }
     $result = $event->getContext()->getSession()->evaluateScript("return window.s");
     if ($result) {
         $title = $event->getLogicalParent()->getTitle();
         $subtitle = $this->getStepText($event);
         $this->collectResult($title, $subtitle, $result);
     }
 }