-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jbcr/main
close session and set test state
- Loading branch information
Showing
6 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/composer.lock | ||
/vendor | ||
/.php_cs.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Version 1.2.0 | ||
|
||
* Fix Lambdatest ending session. | ||
* Before stop the session, define the test execution status on Lambdatest | ||
|
||
# Version 1.1.0 | ||
|
||
* Use the Facebook web driver instead of Selenium2 web driver. | ||
* Before launch, throw an exception if no concurrency automation test is available. | ||
|
||
|
||
# Version 1.0.0 | ||
|
||
* Allow configuring Lambdatest credential with configuration or environment variables. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Macintoshplus\Lambdatest\Driver; | ||
|
||
use Behat\Mink\Exception\DriverException; | ||
use Facebook\WebDriver\Remote\RemoteWebDriver; | ||
|
||
/* | ||
* Override the WebDriver to add quit call on session stop. | ||
* Use the LambdatestWebDriver allow to set the test result on lambdatest. | ||
*/ | ||
final class LambdatestWebDriver extends \SilverStripe\MinkFacebookWebDriver\FacebookWebDriver | ||
{ | ||
protected $webDriver; | ||
|
||
private $started = false; | ||
|
||
public function setWebDriver(RemoteWebDriver $webDriver) | ||
{ | ||
$this->webDriver = $webDriver; | ||
|
||
return parent::setWebDriver($webDriver); | ||
} | ||
|
||
public function stop() | ||
{ | ||
if ($this->isStarted() === false) { | ||
return; | ||
} | ||
|
||
parent::stop(); | ||
|
||
try { | ||
$this->webDriver->quit(); | ||
} catch (Exception $e) { | ||
throw new DriverException('Could not quit connection', 0, $e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Macintoshplus\Lambdatest\Listener; | ||
|
||
use Behat\Mink\Mink; | ||
use Behat\Testwork\EventDispatcher\Event\AfterExerciseCompleted; | ||
use Behat\Testwork\EventDispatcher\Event\ExerciseCompleted; | ||
use Macintoshplus\Lambdatest\Driver\LambdatestWebDriver; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
final class SessionStateListener implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @var Mink | ||
*/ | ||
private $mink; | ||
|
||
/** @var string|null */ | ||
private $javascriptSession; | ||
|
||
/** @var string[] */ | ||
private $javascriptsSessions; | ||
|
||
/** | ||
* SessionStateListener constructor. | ||
* | ||
* @param string|null $javascriptSession | ||
* @param string[] $javascriptsSessions | ||
*/ | ||
public function __construct(Mink $mink, $javascriptSession, array $javascriptsSessions = []) | ||
{ | ||
$this->mink = $mink; | ||
$this->javascriptSession = $javascriptSession; | ||
$this->javascriptsSessions = $javascriptsSessions; | ||
} | ||
|
||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
ExerciseCompleted::AFTER => ['tearDownMinkSessions', 255], | ||
]; | ||
} | ||
|
||
/* | ||
* Define the session test state for all lambdatest session | ||
*/ | ||
public function tearDownMinkSessions(AfterExerciseCompleted $event) | ||
{ | ||
foreach ($this->javascriptsSessions as $sessionName) { | ||
if ($this->mink->hasSession($sessionName) === false) { | ||
continue; | ||
} | ||
$driver = $this->mink->getSession($sessionName)->getDriver(); | ||
if ($driver instanceof LambdatestWebDriver) { | ||
$driver->executeScript('lambda-status='.($event->getTestResult()->isPassed() ? 'passed' : 'failed')); | ||
} | ||
} | ||
} | ||
} |