Skip to content

Commit

Permalink
Added "page" timeout type. Deprecated "page load" and "pageLoad" time…
Browse files Browse the repository at this point in the history
…out types.
  • Loading branch information
aik099 committed Nov 11, 2024
1 parent b324d6e commit 81e6aa7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
16 changes: 11 additions & 5 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,24 @@ public function setTimeouts(array $timeouts)
*/
private function applyTimeouts(): void
{
$validTimeoutTypes = array('script', 'implicit', 'page load', 'pageLoad');
$validTimeoutTypes = array('script', 'implicit', 'page', 'page load', 'pageLoad');

try {
foreach ($this->timeouts as $type => $param) {
if (!in_array($type, $validTimeoutTypes)) {
throw new DriverException('Invalid timeout type: ' . $type);
}

if ($type === 'page load' && $this->isW3C) {
$type = 'pageLoad';
} elseif ($type === 'pageLoad' && !$this->isW3C) {
$type = 'page load';
if ($type === 'page load' || $type === 'pageLoad') {
$type = 'page';
@trigger_error(
'Using "' . $type . '" timeout type is deprecated, please use "page" instead',
E_USER_DEPRECATED
);
}

if ($type === 'page') {
$type = $this->isW3C ? 'pageLoad' : 'page load';
}

if ($this->isW3C) {
Expand Down
28 changes: 22 additions & 6 deletions tests/Custom/TimeoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Behat\Mink\Tests\Driver\Custom;

use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Exception\DriverException;
use Behat\Mink\Tests\Driver\TestCase;

class TimeoutTest extends TestCase
Expand Down Expand Up @@ -36,7 +37,7 @@ public function testInvalidTimeoutSettingThrowsException()
$driver = $session->getDriver();
\assert($driver instanceof Selenium2Driver);

$this->expectException('\Behat\Mink\Exception\DriverException');
$this->expectException(DriverException::class);
$this->expectExceptionMessage('Invalid timeout type: invalid');
$driver->setTimeouts(array('invalid' => 0));
}
Expand Down Expand Up @@ -72,23 +73,38 @@ public function testLongTimeoutWaitsForElementToAppear()
$this->assertNotNull($element);
}

public function testShortPageLoadTimeoutThrowsException()
{
$session = $this->getSession();
$driver = $session->getDriver();
\assert($driver instanceof Selenium2Driver);

$driver->setTimeouts(array('page' => 500));

$this->expectException(DriverException::class);
$this->expectExceptionMessage('Page failed to load: ');
$session->visit($this->pathTo('/page_load.php?sleep=2'));
}

/**
* @dataProvider shortPageLoadTimeoutThrowsExceptionDataProvider
* @group legacy
* @dataProvider deprecatedPageLoadDataProvider
*/
public function testShortPageLoadTimeoutThrowsException(string $timeoutType)
public function testDeprecatedShortPageLoadTimeoutThrowsException(string $type)
{
$session = $this->getSession();
$driver = $session->getDriver();
\assert($driver instanceof Selenium2Driver);

$driver->setTimeouts(array($timeoutType => 500));
$this->expectDeprecation('Using "' . $type . '" timeout type is deprecated, please use "page" instead');

Check failure on line 99 in tests/Custom/TimeoutTest.php

View workflow job for this annotation

GitHub Actions / Static analysis

Method PHPUnit\Framework\TestCase::expectDeprecation() invoked with 1 parameter, 0 required.
$driver->setTimeouts(array($type => 500));

$this->expectException('\Behat\Mink\Exception\DriverException');
$this->expectException(DriverException::class);
$this->expectExceptionMessage('Page failed to load: ');
$session->visit($this->pathTo('/page_load.php?sleep=2'));
}

public static function shortPageLoadTimeoutThrowsExceptionDataProvider(): array
public static function deprecatedPageLoadDataProvider(): array
{
return array(
'w3c style' => array('pageLoad'),
Expand Down

0 comments on commit 81e6aa7

Please sign in to comment.