Skip to content

Commit aee0919

Browse files
committed
Dump browser page when a step fails
1 parent 3688262 commit aee0919

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

stepup/tests/behat/features/bootstrap/FeatureContext.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Surfnet\StepupBehat\ValueObject\Identity;
1313
use Surfnet\StepupBehat\ValueObject\SecondFactorToken;
1414
use Surfnet\StepupBehat\ValueObject\InstitutionConfiguration;
15+
use Behat\Behat\Hook\Scope\AfterStepScope;
1516

1617
class FeatureContext implements Context
1718
{
@@ -450,4 +451,27 @@ public function diePrintingContent()
450451
echo $this->minkContext->getSession()->getPage()->getContent();
451452
die;
452453
}
454+
455+
/**
456+
* @AfterStep
457+
*/
458+
public function dumpPageContentAfterFailedStep(AfterStepScope $scope)
459+
{
460+
if ($scope->getTestResult()->getResultCode() === \Behat\Testwork\Tester\Result\TestResult::FAILED) {
461+
$session = $this->minkContext->getSession();
462+
if ($session->getDriver() instanceof \Behat\Mink\Driver\GoutteDriver) {
463+
$content = $session->getPage()->getContent();
464+
$url = $session->getCurrentUrl();
465+
$headers = $session->getResponseHeaders();
466+
fwrite (STDERR, "\nStep failed:\n");
467+
fwrite (STDERR, "URL: ".$url."\n");
468+
foreach ($headers as $header => $values) {
469+
foreach ($values as $value)
470+
fwrite (STDERR, $header.": ".$value."\n");
471+
}
472+
fwrite(STDERR, "\n".$content."\n");
473+
474+
}
475+
}
476+
}
453477
}

0 commit comments

Comments
 (0)