/**
  * Take screenshot after a failed step
  *
  * @param AfterStepTested $event
  */
 public function checkAfterStep(AfterStepTested $event)
 {
     if ($event->getTestResult()->getResultCode() === TestResult::FAILED) {
         $stepFileName = $this->filenameGenerator->convertStepToFileName($event->getStep());
         $this->screenshotTaker->takeScreenshot($stepFileName);
     }
 }
 public function pauseAfterStep(AfterStepTested $event)
 {
     if (in_array($event->getTestResult()->getResultCode(), array(TestResult::PENDING, TestResult::SKIPPED))) {
         return;
     }
     $this->pauser->pause($event->getStep()->getText());
 }
Beispiel #3
0
 public function getStepResult(AfterStepTested $event)
 {
     array_push($this->results_array, $event->getTestResult()->getResultCode());
     if (preg_match("/I report case result \"([0-9]+)\"\$/", $event->getStep()->getText(), $output_array)) {
         $key = $output_array[1];
         print "Scenario result for case id #" . $key . " ->" . $this->get_result_by_array() . "\n";
         TestRailApiWrapper::log_testcase_result($key, $this->get_result_by_array(), "description");
         // Clean results
         $this->results_array = [];
     }
 }
Beispiel #4
0
 public function provideJsonResponse(AfterStepTested $event)
 {
     $testResult = $event->getTestResult();
     if (!$testResult instanceof ExecutedStepResult) {
         return;
     }
     $callResult = $testResult->getCallResult()->getReturn();
     if (!$callResult instanceof \Behat\Mink\Element\DocumentElement) {
         return;
     }
     $response = $callResult->getContent();
     $this->jsonHolder->setJson($response);
 }
Beispiel #5
0
 /**
  * @param AfterStepTested $event
  */
 public function logFailedStepInformations(AfterStepTested $event)
 {
     $testResult = $event->getTestResult();
     if (!$testResult instanceof TestResult || TestResult::FAILED !== $testResult->getResultCode()) {
         return;
     }
     if (!$this->hasEligibleMinkSession()) {
         return;
     }
     $this->currentDateAsString = date('YmdHis');
     $this->logPageContent();
     if ($this->screenshot) {
         $this->logScreenshot();
     }
 }
 /**
  * Shows last response of failed step with preconfigured command.
  *
  * Configuration is based on `behat.yml`:
  *
  * `show_auto` enable this listener (default to false)
  * `show_cmd` command to run (`open %s` to open default browser on Mac)
  * `show_tmp_dir` folder where to store temp files (default is system temp)
  *
  * @param AfterStepTested $event
  *
  * @throws \RuntimeException if show_cmd is not configured
  */
 public function showFailedStepResponse(AfterStepTested $event)
 {
     $testResult = $event->getTestResult();
     if (!$testResult instanceof ExceptionResult) {
         return;
     }
     if (!$testResult->getException() instanceof MinkException) {
         return;
     }
     if (null === $this->parameters['show_cmd']) {
         throw new \RuntimeException('Set "show_cmd" parameter in behat.yml to be able to open page in browser (ex.: "show_cmd: open %s")');
     }
     $filename = rtrim($this->parameters['show_tmp_dir'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . uniqid() . '.html';
     file_put_contents($filename, $this->mink->getSession()->getPage()->getContent());
     system(sprintf($this->parameters['show_cmd'], escapeshellarg($filename)));
 }
Beispiel #7
0
 public function afterStep(AfterStepTested $event)
 {
     $testResult = $event->getTestResult();
     if (!$testResult instanceof ExecutedStepResult) {
         return;
     }
     $httpCallResult = new HttpCallResult($testResult->getCallResult()->getReturn());
     if ($this->contextSupportedVoter->vote($httpCallResult)) {
         $this->httpCallResultPool->store($httpCallResult);
         return true;
     }
     // For now to avoid modification on MinkContext
     // We add fallback on Mink
     try {
         $this->httpCallResultPool->store(new HttpCallResult($this->mink->getSession()->getPage()->getContent()));
     } catch (\LogicException $e) {
         // Mink has no response
     } catch (\Behat\Mink\Exception\DriverException $e) {
         // No Mink
     }
 }
 /**
  * afterStep callback
  * @param  AfterStepTested $event object
  * @return null
  */
 public function afterStep(AfterStepTested $event)
 {
     $this->testResults->addStepResult($this->currentFeature, $this->currentScenario, $event->getStep(), $event->getTestResult());
     $this->testResults->updateScenarioStatus($this->currentFeature, $this->currentScenario, $event->getTestResult());
     $this->testResults->updateFeatureStatus($this->currentFeature, $event->getTestResult());
 }
Beispiel #9
0
 /**
  * Gets step path from the AFTER test event and exception.
  *
  * @param AfterStepTested $event
  * @param null|Exception  $exception
  *
  * @return string
  */
 private function getStepPath(AfterStepTested $event, Exception $exception = null)
 {
     $path = sprintf('%s:%d', $this->currentFeaturePath, $event->getStep()->getLine());
     if ($exception && $exception instanceof PendingException) {
         $path = $event->getTestResult()->getStepDefinition()->getPath();
     }
     return $path;
 }
 /**
  * @param AfterStepTested $event
  */
 public function onAfterStepTested(AfterStepTested $event)
 {
     $result = $event->getTestResult();
     //$this->dumpObj($event->getStep()->getArguments());
     /** @var Step $step */
     $step = new Step();
     $step->setKeyword($event->getStep()->getKeyword());
     $step->setText($event->getStep()->getText());
     $step->setLine($event->getStep()->getLine());
     $step->setArguments($event->getStep()->getArguments());
     $step->setResult($result);
     $step->setResultCode($result->getResultCode());
     //What is the result of this step ?
     if (is_a($result, 'Behat\\Behat\\Tester\\Result\\UndefinedStepResult')) {
         //pending step -> no definition to load
         $this->pendingSteps[] = $step;
     } else {
         if (is_a($result, 'Behat\\Behat\\Tester\\Result\\SkippedStepResult')) {
             //skipped step
             /** @var ExecutedStepResult $result */
             $step->setDefinition($result->getStepDefinition());
             $this->skippedSteps[] = $step;
         } else {
             //failed or passed
             if ($result instanceof ExecutedStepResult) {
                 $step->setDefinition($result->getStepDefinition());
                 $exception = $result->getException();
                 if ($exception) {
                     $step->setException($exception->getMessage());
                     $this->failedSteps[] = $step;
                 } else {
                     $step->setOutput($result->getCallResult()->getStdOut());
                     $this->passedSteps[] = $step;
                 }
             }
         }
     }
     $this->currentScenario->addStep($step);
     $print = $this->renderer->renderAfterStep($this);
     $this->printer->writeln($print);
 }
 /**
  * Registers undefined step.
  *
  * @param AfterStepTested $event
  */
 public function registerUndefinedStep(AfterStepTested $event)
 {
     if (StepResult::UNDEFINED === $event->getTestResult()->getResultCode()) {
         $this->registry->registerUndefinedStep($event->getEnvironment(), $event->getStep());
     }
 }
 public function afterStep(AfterStepTested $event)
 {
     /** @var ExecutedStepResult $result */
     $result = $event->getTestResult();
     if ($result->getResultCode() === TestResult::FAILED) {
         $exception = $result->getException();
         if ($exception) {
             $this->lastStepFailure = sprintf('%s:%d', $event->getFeature()->getFile(), $event->getStep()->getLine());
             $this->lastStepFailureException = $exception;
         }
     } elseif ($result->getResultCode() === TestResult::PASSED) {
         $this->lastStepFailure = null;
         $this->lastStepFailureException = null;
     }
 }
 /**
  * @param AfterStepTested $event
  */
 public function onAfterStepTested(AfterStepTested $event)
 {
     $result = $event->getTestResult();
     if ($result instanceof ExecutedStepResult) {
         $exception = $result->getException();
         if ($exception) {
             $this->printEvent("testStdErr", array('name' => $exception->getFile(), "out" => $exception->getMessage()));
         }
     }
     $this->printEvent("testStdOut", array('name' => $event->getStep()->getText()));
 }
 public function afterStep(AfterStepTested $event)
 {
     $this->steps[] = new Step($event);
     $this->updateStats("steps", $event->getTestResult()->getResultCode());
 }
 public function getStepResult(AfterStepTested $event)
 {
     array_push($this->results_array, $event->getTestResult()->getResultCode());
     // save message on fail
     if ($event->getTestResult()->getResultCode() == 99) {
         FoxFeatureContext::$stepResultDetails[$event->getStep()->getLine()]['error message'] = $event->getTestResult()->getException()->getMessage();
     }
     if (preg_match("/I report case result \"([0-9]+)\"\$/", $event->getStep()->getText(), $output_array)) {
         $key = $output_array[1];
         print "Scenario result for case id #" . $key . " ->" . $this->get_result_by_array() . "\n";
         TestRailApiWrapper::log_testcase_result($key, $this->get_result_by_array(), $this->buildComment());
         // Clean results
         $this->results_array = [];
         FoxFeatureContext::$stepResultDetails = [];
     }
 }