Пример #1
0
 /**
  * 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);
     }
 }
 function it_generates_filename_from_step_name(ScreenshotTaker $screenshotTaker, StepFilenameGenerator $filenameGenerator, Environment $env, FeatureNode $feature, StepNode $step, StepResult $result, Teardown $tearDown)
 {
     $event = new AfterStepTested($env->getWrappedObject(), $feature->getWrappedObject(), $step->getWrappedObject(), $result->getWrappedObject(), $tearDown->getWrappedObject());
     $result->getResultCode()->willReturn(TestResult::FAILED);
     $filenameGenerator->convertStepToFileName($step)->willReturn('test.jpg')->shouldBeCalled();
     $screenshotTaker->takeScreenshot('test.jpg')->shouldBeCalled();
     $this->checkAfterStep($event);
 }
 /**
  * @param  AfterTested $event
  *
  * @return boolean
  */
 private function shouldSaveScreenshot(AfterTested $event)
 {
     $hasScreenshot = $this->screenshotTaker->hasScreenshot();
     $isScenarioFailed = $event->getTestResult()->getResultCode() === TestResult::FAILED;
     $shouldRecordAllScenarios = $this->config->shouldRecordAllScenarios();
     return $hasScreenshot && ($isScenarioFailed || $shouldRecordAllScenarios);
 }
 function it_does_not_save_screenshot_if_there_isnt_any(ScreenshotTaker $screenshotTaker, ScreenshotUploader $screenshotUploader, FilenameGenerator $filenameGenerator, Environment $env, FeatureNode $feature, ScenarioInterface $scenario, TestResult $result, Teardown $tearDown)
 {
     $event = new AfterScenarioTested($env->getWrappedObject(), $feature->getWrappedObject(), $scenario->getWrappedObject(), $result->getWrappedObject(), $tearDown->getWrappedObject());
     $result->getResultCode()->willReturn(TestResult::FAILED);
     $screenshotTaker->hasScreenshot()->willReturn(false)->shouldBeCalled();
     $filenameGenerator->generateFileName($feature, $scenario)->shouldNotBeCalled();
     $screenshotTaker->getImage()->shouldNotBeCalled();
     $screenshotUploader->upload(Argument::any(), Argument::any())->shouldNotBeCalled();
     $screenshotTaker->reset()->willReturn(null)->shouldBeCalled();
     $this->saveScreenshot($event);
 }