/** * Allow Behat to be killed after the first failed scenario * To enable, in your command prompt run: * export BEHAT_DIE_ON_FAILURE=true; * @AfterScenario * @param AfterScenarioScope $scope */ public function dieOnFailedScenario(AfterScenarioScope $scope) { if (99 === $scope->getTestResult()->getResultCode()) { if (isset($_SERVER['BEHAT_DIE_ON_FAILURE'])) { die("BEHAT_DIE_ON_FAILURE is defined. Killing Full Process\n"); } } }
/** @AfterScenario */ public function printLastResponseWhenScenarioFail(AfterScenarioScope $scope) { if ($scope->getTestResult()->getResultCode() === TestResult::FAILED) { echo "Last response:\n"; echo "Code " . $this->getSession()->getStatusCode() . "\n"; $this->printLastResponse(); } }
/** * @AfterScenario */ public function takeDatabaseDumpAfterFailedStep(AfterScenarioScope $scope) { if ($this->screenshot_dir && TestResult::FAILED === $scope->getTestResult()->getResultCode()) { $feature = $scope->getFeature(); $scenario = $scope->getScenario(); $filename = basename($feature->getFile(), '.feature') . '-' . $scenario->getLine(); $filepath = $this->screenshot_dir . $filename . '.sql'; try { $dump = new Mysqldump('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD); $dump->start($filepath); } catch (\Exception $e) { echo 'mysqldump-php error: ' . $e->getMessage(); } } }
protected function dieOnFailedScenario(AfterScenarioScope $scope) { if (99 === $scope->getTestResult()->getResultCode()) { if (isset($_SERVER['BEHAT_DIE_ON_FAILURE'])) { die("\n\nBEHAT_DIE_ON_FAILURE is defined\n\nKilling Full Process\n\n\n\n"); } else { echo "\n\nTo die on failure, please run:\nexport BEHAT_DIE_ON_FAILURE=true;\n\n"; } } }
/** * @param AfterScenarioScope $scope */ public function printTesterOutputOnFailure($scope) { if (!$scope->getTestResult()->isPassed()) { $outputFile = sys_get_temp_dir() . '/behat-test-runner.out'; $this->filesystem->dumpFile($outputFile, $this->behatProcess->getOutput() . $this->behatProcess->getErrorOutput()); throw new RuntimeException("Output of secondary Behat process has been saved to {$outputFile}"); } }