コード例 #1
0
 /**
  * @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;
 }
コード例 #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);
                 }
             }
         }
     }
 }