From 61d0144b29765ed55e3a256ba712cffefbc4bd52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 11 May 2021 12:59:38 +0200 Subject: [PATCH] dump context extends raw context --- src/Behat/{ContextDump.php => DumpContext.php} | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) rename src/Behat/{ContextDump.php => DumpContext.php} (61%) diff --git a/src/Behat/ContextDump.php b/src/Behat/DumpContext.php similarity index 61% rename from src/Behat/ContextDump.php rename to src/Behat/DumpContext.php index 79c09fa45e..c586fd4fc7 100644 --- a/src/Behat/ContextDump.php +++ b/src/Behat/DumpContext.php @@ -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. @@ -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"; }