diff --git a/.gitignore b/.gitignore index ff72e2d..bd73404 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /composer.lock /vendor +/.php_cs.cache diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..41efaa9 --- /dev/null +++ b/CHANGELOG.md @@ -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. diff --git a/src/Driver/LambdatestFactory.php b/src/Driver/LambdatestFactory.php index de2cc01..f206277 100644 --- a/src/Driver/LambdatestFactory.php +++ b/src/Driver/LambdatestFactory.php @@ -63,6 +63,9 @@ public function buildDriver(array $config) throw new TooManyParallelExecutionException(sprintf('Unable to launch anothe parallel automation test. max concurency: %s, current running test: %s', $data['data']['max_concurrency'], $data['data']['running'])); } - return parent::buildDriver($config); + $def = parent::buildDriver($config); + $def->setClass(LambdatestWebDriver::class); + + return $def; } } diff --git a/src/Driver/LambdatestWebDriver.php b/src/Driver/LambdatestWebDriver.php new file mode 100644 index 0000000..96b3739 --- /dev/null +++ b/src/Driver/LambdatestWebDriver.php @@ -0,0 +1,41 @@ +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); + } + } +} diff --git a/src/LambdatestExtension.php b/src/LambdatestExtension.php index 1162a29..50740c3 100644 --- a/src/LambdatestExtension.php +++ b/src/LambdatestExtension.php @@ -3,10 +3,13 @@ namespace Macintoshplus\Lambdatest; use Behat\MinkExtension\ServiceContainer\MinkExtension; +use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension; use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface; use Behat\Testwork\ServiceContainer\ExtensionManager; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Reference; class LambdatestExtension implements ExtensionInterface { @@ -41,6 +44,14 @@ public function configure(ArrayNodeDefinition $builder) */ public function load(ContainerBuilder $container, array $config) { + //SessionStateListener + $definition = new Definition('Macintoshplus\Lambdatest\Listener\SessionStateListener', [ + new Reference(MinkExtension::MINK_ID), + '%mink.javascript_session%', + '%mink.available_javascript_sessions%', + ]); + $definition->addTag(EventDispatcherExtension::SUBSCRIBER_TAG, ['priority' => 0]); + $container->setDefinition('mink.lambdatest.listener.sessions', $definition); } /** diff --git a/src/Listener/SessionStateListener.php b/src/Listener/SessionStateListener.php new file mode 100644 index 0000000..b0028eb --- /dev/null +++ b/src/Listener/SessionStateListener.php @@ -0,0 +1,61 @@ +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')); + } + } + } +}