Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
Print out the page contents after any failed test.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Jan 1, 2017
1 parent c5aebeb commit b663112
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\DrupalExtension\Context\MinkContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\Behat\Hook\Scope\AfterStepScope;

use Drupal\DrupalExtension\Context\RawDrupalContext;

Expand Down Expand Up @@ -213,4 +214,37 @@ public function spin ($lambda, $wait = 60)

return false;
}

/**
* @AfterStep
*/
public function afterStep(AfterStepScope $scope)
{
// Do nothing on steps that pass
$result = $scope->getTestResult();
if ($result->isPassed()) {
return;
}

// Otherwise, dump the page contents.
$session = $this->getSession();
$page = $session->getPage();
$html = $page->getContent();
$html = static::trimHead($html);

print "::::::::::::::::::::::::::::::::::::::::::::::::\n";
print $html . "\n";
print "::::::::::::::::::::::::::::::::::::::::::::::::\n";
}

/**
* Remove everything in the '<head>' element except the
* title, because it is long and uninteresting.
*/
protected static function trimHead($html)
{
$html = preg_replace('#\<head\>.*\<title\>#sU', '<head><title>', $html);
$html = preg_replace('#\</title\>.*\</head\>#sU', '</title></head>', $html);
return $html;
}
}

3 comments on commit b663112

@pantheon-upstream
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created multidev environment ci-example-d8-composer#ci-205.

Visit Site

@pantheon-upstream
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created multidev environment ci-example-d8-composer#ci-208.

Visit Site

@pantheon-upstream
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created multidev environment ci-example-d8-composer#ci-209.

Visit Site

Please sign in to comment.