Last active
May 2, 2016 08:22
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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()); | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.