Skip to content

Instantly share code, notes, and snippets.

@tentacode
Last active May 2, 2016 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tentacode/c7a587e141315b4e41328121e0c4077f to your computer and use it in GitHub Desktop.
Save tentacode/c7a587e141315b4e41328121e0c4077f to your computer and use it in GitHub Desktop.
Doing something with the exception message after a failing behat scenario using @afterstep.
<?php
namespace Context;
use Behat\Behat\Hook\Scope\AfterStepScope;
use Behat\Testwork\Tester\Result\ExceptionResult;
class DebugContext extends BaseContext
{
/**
* @AfterStep
*/
public function doSomethingOnFailed(AfterStepScope $event)
{
// not an error
if (!$event->getTestResult() instanceof ExceptionResult) {
return;
}
$step = $event->getStep();
print sprintf("Step that failed : %s\n", $step->getText());
$exception = $event->getTestResult()->getException();
print sprintf("Exception was : %s\n", $exception->getMessage());
}
// ...
}
@tentacode
Copy link
Author

FYI I have not actually tested this, if it does not work, try and look at Behat API.

@roycollings
Copy link

Hey Tentacode - 'getException' doesn't seem to be an option in v3 (I only get getResultCode and isPassed as options here). Any idea where it went, I can't find any reference to it after v2.5 of the Behat api docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment