/**
  * @param BaseScenarioEvent $event
  *
  * @AfterScenario
  */
 public function resetCurrentPage(BaseScenarioEvent $event)
 {
     if ($event->getResult() !== StepEvent::UNDEFINED) {
         $script = 'sessionStorage.clear(); typeof $ !== "undefined" && $(window).off("beforeunload");';
         $this->getMainContext()->executeScript($script);
     }
     $this->currentPage = null;
 }
Ejemplo n.º 2
0
 /**
  * @AfterScenario
  */
 public function printLastResponseOnError(BaseScenarioEvent $scenarioEvent)
 {
     if ($scenarioEvent->getResult() == StepEvent::FAILED) {
         if ($this->response) {
             $body = $this->getResponse()->getBody(true);
             // could we even ask them if they want to print out the error?
             // or do it based on verbosity
             // print some debug details
             $this->printDebug('');
             $this->printDebug('<error>Failure!</error> when making the following request:');
             $this->printDebug(sprintf('<comment>%s</comment>: <info>%s</info>', $this->lastRequest->getMethod(), $this->lastRequest->getUrl()) . "\n");
             if ($this->response->isContentType('application/json') || $this->response->isContentType('+json')) {
                 $data = json_decode($body);
                 if ($data === null) {
                     // invalid JSON!
                     $this->printDebug($body);
                 } else {
                     // valid JSON, print it pretty
                     $this->printDebug(json_encode($data, JSON_PRETTY_PRINT));
                 }
             } else {
                 // the response is HTML - see if we should print all of it or some of it
                 $isValidHtml = strpos($body, '</body>') !== false;
                 if ($this->useFancyExceptionReporting && $isValidHtml) {
                     $this->printDebug('<error>Failure!</error> Below is a summary of the HTML response from the server.');
                     // finds the h1 and h2 tags and prints them only
                     $crawler = new Crawler($body);
                     foreach ($crawler->filter('h1, h2')->extract(array('_text')) as $header) {
                         $this->printDebug(sprintf('        ' . $header));
                     }
                 } else {
                     $this->printDebug($body);
                 }
             }
         }
     }
 }
 /**
  * Initializes outline example event.
  *
  * @param OutlineNode      $outline
  * @param integer          $iteration iteration number
  * @param ContextInterface $context
  * @param integer          $result
  * @param Boolean          $skipped
  */
 public function __construct(OutlineNode $outline, $iteration, ContextInterface $context, $result = null, $skipped = false)
 {
     parent::__construct($context, $result, $skipped);
     $this->outline = $outline;
     $this->iteration = $iteration;
 }
Ejemplo n.º 4
0
 /**
  * Initializes scenario event.
  *
  * @param ScenarioNode     $scenario
  * @param ContextInterface $context
  * @param integer          $result
  * @param Boolean          $skipped
  */
 public function __construct(ScenarioNode $scenario, ContextInterface $context, $result = null, $skipped = false)
 {
     $this->scenario = $scenario;
     parent::__construct($context, $result, $skipped);
 }