Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distribute Behat Context #1628

Merged
merged 2 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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