/**
  * {@inheritdoc}
  */
 public function tearDown(Environment $env, FeatureNode $feature, StepNode $step, $skip, StepResult $result)
 {
     $event = new BeforeStepTeardown($env, $feature, $step, $result);
     $this->eventDispatcher->dispatch($event::BEFORE_TEARDOWN, $event);
     $teardown = $this->baseTester->tearDown($env, $feature, $step, $skip, $result);
     $event = new AfterStepTested($env, $feature, $step, $result, $teardown);
     $this->eventDispatcher->dispatch($event::AFTER, $event);
     return $teardown;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function tearDown(Environment $env, FeatureNode $feature, StepNode $step, $skip, StepResult $result)
 {
     $teardown = $this->baseTester->tearDown($env, $feature, $step, $skip, $result);
     if ($skip) {
         return $teardown;
     }
     $scope = new AfterStepScope($env, $feature, $step, $result);
     $hookCallResults = $this->hookDispatcher->dispatchScopeHooks($scope);
     return new HookedTeardown($teardown, $hookCallResults);
 }
예제 #3
0
 /**
  * @param array $steps
  * @param Suite $suite
  * @return \Behat\Behat\Tester\Result\StepResult
  */
 public function run($steps, Suite $suite)
 {
     $env = $this->environmentManager->buildEnvironment($suite);
     $env = $this->environmentManager->isolateEnvironment($env);
     $dummyFeatureNode = $this->generator->generate($steps);
     $featureNode = $dummyFeatureNode->getFeatureNode();
     foreach ($dummyFeatureNode->getStepNodes() as $stepNode) {
         $this->stepTester->setUp($env, $featureNode, $stepNode, false);
         $result = $this->stepTester->test($env, $featureNode, $stepNode, false);
         $this->stepTester->tearDown($env, $featureNode, $stepNode, false, $result);
     }
     return $result;
 }
예제 #4
0
 /**
  * Tests container.
  *
  * @param Environment            $env
  * @param FeatureNode            $feature
  * @param StepContainerInterface $container
  * @param Boolean                $skip
  *
  * @return TestResult[]
  */
 public function test(Environment $env, FeatureNode $feature, StepContainerInterface $container, $skip)
 {
     $results = array();
     foreach ($container->getSteps() as $step) {
         $setup = $this->stepTester->setUp($env, $feature, $step, $skip);
         $skipSetup = !$setup->isSuccessful() || $skip;
         $testResult = $this->stepTester->test($env, $feature, $step, $skipSetup);
         $skip = !$testResult->isPassed() || $skip;
         $teardown = $this->stepTester->tearDown($env, $feature, $step, $skipSetup, $testResult);
         $skip = $skip || $skipSetup || !$teardown->isSuccessful();
         $integerResult = new IntegerTestResult($testResult->getResultCode());
         $results[] = new TestWithSetupResult($setup, $integerResult, $teardown);
     }
     return $results;
 }
예제 #5
0
 /**
  * Executes provided step definition.
  *
  * If the result is not a failure then take a screenshot and compare for differences.
  *
  * @param StepNode $step
  * @param DefinitionInterface $definition
  * @throws PerceptualDiffException If there are differences compared to the baseline
  */
 protected function executeStepDefinition(StepNode $step, DefinitionInterface $definition)
 {
     parent::executeStepDefinition($step, $definition);
     $diff = $this->screenshotComparator->takeScreenshot($this->context, $step);
     if ($diff > 0 && $this->failOnDiff) {
         // There were differences between the two screenshots
         throw new PerceptualDiffException(sprintf('There was a perceptual difference of %d', $diff));
     }
 }
 /**
  * Executes provided step definition.
  *
  * If the result is not a failure then take a screenshot and compare for differences.
  *
  * @param StepNode $step
  * @param DefinitionInterface $definition
  * @throws PerceptualDiffException If there are differences compared to the baseline
  */
 protected function executeStepDefinition(StepNode $step, DefinitionInterface $definition)
 {
     parent::executeStepDefinition($step, $definition);
     $session = $this->context->getSession();
     // give JavaScript time to trigger additional ajax requests after onload
     $session->wait(100);
     // Wait for an ajax request to complete, but only for a maximum of X seconds to avoid deadlocks
     $session->wait(5000, "(typeof window.__ajaxStatus !== 'undefined' ? window.__ajaxStatus() : 'no ajax') !== 'waiting'");
     // The 'sleep' config setting will be respected in the comparator logic,
     // and is required to be at least ~200ms to give the browser a chance to finish rendering
     $diff = $this->screenshotComparator->takeScreenshot($this->context, $step);
     if ($diff > 0 && $this->failOnDiff) {
         // There were differences between the two screenshots
         throw new PerceptualDiffException(sprintf('There was a perceptual difference of %d', $diff));
     }
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function tearDown(Environment $env, FeatureNode $feature, StepNode $step, $skip, StepResult $result)
 {
     return $this->baseTester->tearDown($env, $feature, $step, $skip, $result);
 }
 /**
  * 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;
 }