Skip to content

Commit

Permalink
Distribute Behat Context (#1628)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored May 11, 2021
1 parent dbb3557 commit 3decddd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@
},
"autoload-dev": {
"psr-4": {
"Atk4\\Ui\\Tests\\": "tests/",
"Atk4\\Ui\\Behat\\": "tests-behat/bootstrap/"
"Atk4\\Ui\\Tests\\": "tests/"
}
},
"minimum-stability": "dev",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

namespace Atk4\Ui\Behat;

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

/**
* 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 +18,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 3decddd

Please sign in to comment.