Skip to content

Instantly share code, notes, and snippets.

@gormster
Created July 1, 2019 03:58
Show Gist options
  • Save gormster/8829d6f86b473b47d868c9bc42cd5237 to your computer and use it in GitHub Desktop.
Save gormster/8829d6f86b473b47d868c9bc42cd5237 to your computer and use it in GitHub Desktop.
Behat - pause on step failure
// Replace with your favourite way of requiring a file.
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
use Behat\Behat\Hook\Scope\AfterStepScope;
use Behat\Testwork\Tester\Result\TestResult;
// Uncomment this line to enable the debug step.
// define('DEBUG',1);
// Make sure to rename this class (and the file!) with your plugin's namespace.
class behat_example_plugin extends behat_base {
/**
* Allow debugging of behat tests by PAUSING on failure.
* Uncomment the DEBUG define above to use it. This should really be a built in part of Behat IMO...
* @AfterStep
*
* @param AfterStepScope $scope
*/
public function wait_to_debug_in_browser_on_step_error(AfterStepScope $scope) {
if (defined('DEBUG')) {
if ($scope->getTestResult()->getResultCode() == TestResult::FAILED) {
// \x07 = BEL character, so the TTY makes a sound to let you know a failure happened.
fwrite(STDOUT, PHP_EOL . "\x07PAUSING ON FAILURE - Press any key to continue" . PHP_EOL);
fflush(STDOUT);
$anything = fread(STDIN, 1);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment