Skip to content

Commit

Permalink
dump context extends raw context
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed May 11, 2021
1 parent cd7fe16 commit de3c660
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Behat/ContextDump.php → src/Behat/DumpContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

namespace Atk4\Ui\Behat;

use Behat\Behat\Context\Context as BehatContext;
use Behat\Behat\Hook\Scope\AfterStepScope;
use Behat\Testwork\Tester\Result\TestResult;
use Behat\MinkExtension\Context\RawMinkContext;

/**
* Dump page data when failed.
*/
class ContextDump extends Context
class DumpContext extends RawMinkContext implements BehatContext
{
/**
* Dump current page data when step failed for CI.
Expand All @@ -19,16 +17,18 @@ class ContextDump extends Context
*/
public function dumpPageAfterFailedStep(AfterStepScope $event): void
{
$session = $this->getMink()->getSession();;

if ($event->getTestResult()->getResultCode() === TestResult::FAILED) {
if ($this->getSession()->getDriver() instanceof \Behat\Mink\Driver\Selenium2Driver) {
if ($session->getDriver() instanceof \Behat\Mink\Driver\Selenium2Driver) {
echo 'Dump of failed step:' . "\n";
echo 'Current page URL: ' . $this->getSession()->getCurrentUrl() . "\n";
echo 'Current page URL: ' . $session->getCurrentUrl() . "\n";
global $dumpPageCount;
if (++$dumpPageCount <= 1) { // prevent huge tests output
// upload screenshot here if needed in the future
// $screenshotData = $this->getSession()->getScreenshot();
// $screenshotData = $session->getScreenshot();
// echo 'Screenshot URL: ' . $screenshotUrl . "\n";
echo 'Page source: ' . $this->getSession()->getPage()->getContent() . "\n";
echo 'Page source: ' . $session->getPage()->getContent() . "\n";
} else {
echo 'Page source: Source code is dumped for the first failed step only.' . "\n";
}
Expand Down

0 comments on commit de3c660

Please sign in to comment.