Skip to content

Commit

Permalink
Merge pull request #13 from jbcr/main
Browse files Browse the repository at this point in the history
change option split_video
  • Loading branch information
macintoshplus authored Apr 28, 2023
2 parents 140a715 + cddfe26 commit 0592686
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ default:
# You can use the LT_USERNAME and LT_USERKEY environment variables instead of this keys:
user: [email protected] # Your Lambdatest login
key: xxxxx # Your Lambdatest key available here: https://accounts.lambdatest.com/detail/profile
split_video: false #If false, run all scenario in one session. If true, close and open a new session for each scenario
restart_session_between_scenario: false #If false, run all scenario in one session. If true, close and open a new session for each scenario
# The rest of key are the same as Mink Extension
wd_host: https://hub.lambdatest.com/wd/hub # The URL of Selenium2 Hub
capabilities:
name: Behat test suite # Define the name to change the Lambdatest session name or prefix if `split_video` is true
name: Behat test suite # Define the name to change the Lambdatest session name or prefix if `restart_session_between_scenario` is true
# The rest of key are the same as Mink Extension
browser: firefox # The browser name
marionette: true
Expand Down
4 changes: 2 additions & 2 deletions src/Driver/LambdatestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function configure(ArrayNodeDefinition $builder)
$builder->children()
->scalarNode('user')->end()
->scalarNode('key')->end()
->booleanNode('split_video')->defaultFalse()->end()
->booleanNode('restart_session_between_scenario')->defaultFalse()->end()
->end();
parent::configure($builder);
}
Expand Down Expand Up @@ -71,7 +71,7 @@ public function buildDriver(array $config)

$def = parent::buildDriver($config);
$def->setClass(LambdatestWebDriver::class);
$def->setArgument(3, $config['split_video']);
$def->setArgument(3, $config['restart_session_between_scenario']);
$capabilities = $def->getArgument(1);

// Remove w3c option is no Chrome browser
Expand Down
15 changes: 7 additions & 8 deletions src/Driver/LambdatestWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,32 @@
use Facebook\WebDriver\Exception\InvalidSessionIdException;
use Facebook\WebDriver\Exception\UnrecognizedExceptionException;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use SilverStripe\MinkFacebookWebDriver\FacebookWebDriver;

/*
* 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
final class LambdatestWebDriver extends FacebookWebDriver
{
protected $webDriver;

private $started = false;

private bool $splitVideo;
private bool $restartSessionBetweenScenario;

public function __construct(
$browserName = self::DEFAULT_BROWSER,
$desiredCapabilities = [],
$wdHost = 'http://localhost:4444/wd/hub',
$splitVideo = false
$restartSessionBetweenScenario = false
) {
parent::__construct($browserName, $desiredCapabilities, $wdHost);
$this->splitVideo = $splitVideo;
$this->restartSessionBetweenScenario = $restartSessionBetweenScenario;
}

public function isSplitVideo(): bool
public function isRestartSessionBetweenScenario(): bool
{
return $this->splitVideo;
return $this->restartSessionBetweenScenario;
}

public function setWebDriver(RemoteWebDriver $webDriver)
Expand Down
6 changes: 3 additions & 3 deletions src/Listener/SessionStateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function tearDownMinkSessions($event)
public function beforeScenario(BeforeScenarioTested $event): void
{
$driver = $this->getMinkLambdatestSession();
if ($driver === null || $driver->isSplitVideo() === false) {
if ($driver === null || $driver->isRestartSessionBetweenScenario() === false) {
return;
}
if (empty($this->originalTags)) {
Expand All @@ -113,7 +113,7 @@ public function beforeScenario(BeforeScenarioTested $event): void
public function afterScenarioOrOutline(AfterTested $event): void
{
$driver = $this->getMinkLambdatestSession();
if ($driver === null || $driver->getWebDriver() === null || $driver->isSplitVideo() === false) {
if ($driver === null || $driver->getWebDriver() === null || $driver->isRestartSessionBetweenScenario() === false) {
return;
}
$driver->executeScript('lambda-status='.($event->getTestResult()->isPassed() ? 'passed' : 'failed'));
Expand All @@ -127,7 +127,7 @@ public function afterScenarioOrOutline(AfterTested $event): void
public function beforeOutline(BeforeOutlineTested $event): void
{
$driver = $this->getMinkLambdatestSession();
if ($driver === null || $driver->isSplitVideo() === false) {
if ($driver === null || $driver->isRestartSessionBetweenScenario() === false) {
return;
}
if (empty($this->originalTags)) {
Expand Down

0 comments on commit 0592686

Please sign in to comment.