Skip to content

Commit

Permalink
Support MinkSelenium2Driver page timeout (#38)
Browse files Browse the repository at this point in the history
* Support MinkSelenium2Driver page timeout

* Trigger deprecation of old-style page timeout

* Replace duplicate code with comment

* Test deprecations

* Rework custom tests to not depend on magic setup

* Set up standard defaults to avoid contaminated sessions

* [debug] Only run tests that fail

* [debug] Adjusted PHPUnit 10 test filtering expression to work on PHPUnit 9

* [debug] remove irrelevant (for debugging) build config sections to speed it up

* [debug] Reduce matrix size even more

* Don't let driver define Selenium Server default timeouts

* [debug] confirm, that timeout tests executed at the beginning would break window tests down the road

* Revert "[debug] confirm, that timeout tests executed at the beginning would break window tests down the road"

This reverts commit b33289b.

* [debug] see if Selenium actually sets timeouts as needed

* Don't reset timeout at the test end, because new driver instance is created in setup

* [debug] PhpStan fix

* [debug] see if session with incorrect timeout is shared between tests

* Fixed formatting error

* [debug] see if deprecation catching causes timeout issues

* [debug] see of sleepy page causes a timeout issue

* [debug] change data provider declaration of the timeouts test

* [debug] removed debug output in the driver code, because not timeouts are causing the issue with window test

* [debug] Look inside GitHub Actions with an SSH session

* [debug] start web server outside of PHPUnit bootstrap file

* [debug] remove unrelated build config parts

* [debug] corrected host of locally started mink server

* [debug] corrected hostname for started web server checking

* [debug] another try to get local web server running

* [debug] reduce test count to figure out why web server is not working

* [debug] Experiment with WEB_FIXTURES_HOST env var detection

* [debug] another try to debug what URL is actually used by test suite

* [debug] another try

* Allow overriding env vars from "phpunit.xml.dist" via env vars from GitHub Actions

* [debug] removed some of the debug code

* [debug] change local web server detection code to avoid it's crashing in the checking process

* [debug] try to make web server available for Selenium Server

* [debug] undo experimental port mapping

* [debug] attempt to start web sever on all ips

* [debug] rolled back CI code that reduced build count

* [debug] rolled back the debug code, that started web server outside of PHPUnit code

* rolled back changes to "phpunit.xml.dist" (to be discussed in other issue)

* Partially skip short "pageLoad" timeout test in Google Chrome

* Fully skip short "pageLoad" timeout test in Google Chrome

* Only skip test added in this PR for Google Chrome

* Apparently "chromium" and "edge" browsers also freeze, when setting "pageLoad" timeout several times. So skip test in there as well.

* Exclude timeout deprecation test only on GitHub Actions

* Minor test fixes and improvements

* Disable test on old firefox

* Fix minkphp/MinkSelenium2Driver#391

---------

Co-authored-by: Alex <[email protected]>
  • Loading branch information
uuf6429 and aik099 authored Nov 12, 2024
1 parent 8e3c6ca commit ca55cde
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 17 deletions.
8 changes: 8 additions & 0 deletions src/WebdriverClassicDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,14 @@ private function applyTimeouts(): void
$timeouts->implicitlyWait($param / 1000);
break;

case 'page load':
case 'pageLoad':
@trigger_error(
"Using \"$type\" timeout type is deprecated, please use \"page\" instead",
E_USER_DEPRECATED
);
// no break

case 'page':
$timeouts->pageLoadTimeout($param / 1000);
break;
Expand Down
2 changes: 1 addition & 1 deletion tests/Custom/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function getConfig(): WebdriverClassicConfig
*/
protected function checkSkippedTest(): void
{
$message = self::getConfig()->skipMessage(get_class($this), $this->getName(false));
$message = $this->getConfig()->skipMessage(static::class, $this->getName(false));

if (null !== $message) {
$this->markTestSkipped($message);
Expand Down
33 changes: 22 additions & 11 deletions tests/Custom/TimeoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@

class TimeoutTest extends TestCase
{
protected function tearDown(): void
{
$this->driver->setTimeouts([
'script' => 30000,
'page' => 300000,
'implicit' => 0,
]);

parent::tearDown();
}

public function testInvalidTimeoutSettingThrowsException(): void
{
$this->driver->start();
Expand Down Expand Up @@ -59,4 +48,26 @@ public function testShortPageLoadTimeoutThrowsException(): void

$this->driver->visit($this->pathTo('/page_load.php?sleep=2'));
}

/**
* @group legacy
* @dataProvider deprecatedPageLoadDataProvider
*/
public function testDeprecatedShortPageLoadTimeoutThrowsException(string $type): void
{
$this->driver->start();

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

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

public static function deprecatedPageLoadDataProvider(): iterable
{
yield 'selenium 3 style' => ['type' => 'pageLoad'];
yield 'selenium 2 style' => ['type' => 'page load'];
}
}
31 changes: 26 additions & 5 deletions tests/WebdriverClassicConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Behat\Mink\Tests\Driver\Basic\HeaderTest;
use Behat\Mink\Tests\Driver\Basic\StatusCodeTest;
use Behat\Mink\Tests\Driver\Js\EventsTest;
use Behat\Mink\Tests\Driver\Js\JavascriptTest;
use Behat\Mink\Tests\Driver\Js\WindowTest;
use Mink\WebdriverClassicDriver\Tests\Custom\TimeoutTest;
use Mink\WebdriverClassicDriver\WebdriverClassicDriver;

class WebdriverClassicConfig extends AbstractConfig
Expand Down Expand Up @@ -43,7 +45,8 @@ public function mapRemoteFilePath($file): string
public function skipMessage($testCase, $test): ?string
{
switch (true) {
case $testCase === WindowTest::class && $test === 'testWindowMaximize' && $this->isXvfb():
case [$testCase, $test] === [WindowTest::class, 'testWindowMaximize']
&& $this->isXvfb():
return 'Maximizing the window does not work when running the browser in Xvfb.';

case $testCase === BasicAuthTest::class:
Expand All @@ -55,17 +58,24 @@ public function skipMessage($testCase, $test): ?string
case $testCase === StatusCodeTest::class:
return 'Checking status code is not supported.';

case $testCase === EventsTest::class && $test === 'testKeyboardEvents' && $this->isOldChrome():
case [$testCase, $test] === [EventsTest::class, 'testKeyboardEvents']
&& $this->isOldChrome():
return 'Old Chrome does not allow triggering events.';

case [$testCase, $test] === [TimeoutTest::class, 'testDeprecatedShortPageLoadTimeoutThrowsException']
&& ($this->isChromiumBased() || $this->isOldFirefox())
&& $this->isXvfb():
return 'Setting page load timeout several times causes a freeze in this browser.';

case [$testCase, $test] === [JavascriptTest::class, 'testDragDropOntoHiddenItself']
&& $this->isOldFirefox():
return 'The Firefox browser compatible with Selenium Server 2.x does not fully implement drag-n-drop support.';

default:
return parent::skipMessage($testCase, $test);
}
}

/**
* {@inheritdoc}
*/
protected function supportsCss(): bool
{
return true;
Expand All @@ -81,4 +91,15 @@ private function isOldChrome(): bool
return getenv('WEB_FIXTURES_BROWSER') === 'chrome'
&& version_compare(getenv('SELENIUM_VERSION') ?: '', '3', '<');
}

private function isOldFirefox(): bool
{
return getenv('WEB_FIXTURES_BROWSER') === 'firefox'
&& version_compare(getenv('SELENIUM_VERSION') ?: '', '3', '<');
}

private function isChromiumBased(): bool
{
return in_array($this->getBrowserName(), ['chrome', 'chromium', 'edge']);
}
}

0 comments on commit ca55cde

Please sign in to comment.