From 81e6aa7ef93d2349d95fb340bc859c6a3bf4b78d Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 11 Nov 2024 11:22:21 +0200 Subject: [PATCH] Added "page" timeout type. Deprecated "page load" and "pageLoad" timeout types. --- src/Selenium2Driver.php | 16 +++++++++++----- tests/Custom/TimeoutTest.php | 28 ++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index 242096a..3e9d599 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -386,7 +386,7 @@ 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) { @@ -394,10 +394,16 @@ private function applyTimeouts(): void 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) { diff --git a/tests/Custom/TimeoutTest.php b/tests/Custom/TimeoutTest.php index 7c52de1..d7bf918 100644 --- a/tests/Custom/TimeoutTest.php +++ b/tests/Custom/TimeoutTest.php @@ -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 @@ -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)); } @@ -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'); + $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'),