Skip to content

Commit ca55cde

Browse files
uuf6429aik099
andauthored
Support MinkSelenium2Driver page timeout (#38)
* 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 <aik099@users.noreply.github.com>
1 parent 8e3c6ca commit ca55cde

File tree

4 files changed

+57
-17
lines changed

4 files changed

+57
-17
lines changed

src/WebdriverClassicDriver.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,14 @@ private function applyTimeouts(): void
961961
$timeouts->implicitlyWait($param / 1000);
962962
break;
963963

964+
case 'page load':
965+
case 'pageLoad':
966+
@trigger_error(
967+
"Using \"$type\" timeout type is deprecated, please use \"page\" instead",
968+
E_USER_DEPRECATED
969+
);
970+
// no break
971+
964972
case 'page':
965973
$timeouts->pageLoadTimeout($param / 1000);
966974
break;

tests/Custom/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function getConfig(): WebdriverClassicConfig
4343
*/
4444
protected function checkSkippedTest(): void
4545
{
46-
$message = self::getConfig()->skipMessage(get_class($this), $this->getName(false));
46+
$message = $this->getConfig()->skipMessage(static::class, $this->getName(false));
4747

4848
if (null !== $message) {
4949
$this->markTestSkipped($message);

tests/Custom/TimeoutTest.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66

77
class TimeoutTest extends TestCase
88
{
9-
protected function tearDown(): void
10-
{
11-
$this->driver->setTimeouts([
12-
'script' => 30000,
13-
'page' => 300000,
14-
'implicit' => 0,
15-
]);
16-
17-
parent::tearDown();
18-
}
19-
209
public function testInvalidTimeoutSettingThrowsException(): void
2110
{
2211
$this->driver->start();
@@ -59,4 +48,26 @@ public function testShortPageLoadTimeoutThrowsException(): void
5948

6049
$this->driver->visit($this->pathTo('/page_load.php?sleep=2'));
6150
}
51+
52+
/**
53+
* @group legacy
54+
* @dataProvider deprecatedPageLoadDataProvider
55+
*/
56+
public function testDeprecatedShortPageLoadTimeoutThrowsException(string $type): void
57+
{
58+
$this->driver->start();
59+
60+
$this->expectDeprecation('Using "' . $type . '" timeout type is deprecated, please use "page" instead');
61+
$this->driver->setTimeouts([$type => 500]);
62+
63+
$this->expectException(DriverException::class);
64+
$this->expectExceptionMessage('Page failed to load: ');
65+
$this->driver->visit($this->pathTo('/page_load.php?sleep=2'));
66+
}
67+
68+
public static function deprecatedPageLoadDataProvider(): iterable
69+
{
70+
yield 'selenium 3 style' => ['type' => 'pageLoad'];
71+
yield 'selenium 2 style' => ['type' => 'page load'];
72+
}
6273
}

tests/WebdriverClassicConfig.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
use Behat\Mink\Tests\Driver\Basic\HeaderTest;
88
use Behat\Mink\Tests\Driver\Basic\StatusCodeTest;
99
use Behat\Mink\Tests\Driver\Js\EventsTest;
10+
use Behat\Mink\Tests\Driver\Js\JavascriptTest;
1011
use Behat\Mink\Tests\Driver\Js\WindowTest;
12+
use Mink\WebdriverClassicDriver\Tests\Custom\TimeoutTest;
1113
use Mink\WebdriverClassicDriver\WebdriverClassicDriver;
1214

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

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

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

65+
case [$testCase, $test] === [TimeoutTest::class, 'testDeprecatedShortPageLoadTimeoutThrowsException']
66+
&& ($this->isChromiumBased() || $this->isOldFirefox())
67+
&& $this->isXvfb():
68+
return 'Setting page load timeout several times causes a freeze in this browser.';
69+
70+
case [$testCase, $test] === [JavascriptTest::class, 'testDragDropOntoHiddenItself']
71+
&& $this->isOldFirefox():
72+
return 'The Firefox browser compatible with Selenium Server 2.x does not fully implement drag-n-drop support.';
73+
6174
default:
6275
return parent::skipMessage($testCase, $test);
6376
}
6477
}
6578

66-
/**
67-
* {@inheritdoc}
68-
*/
6979
protected function supportsCss(): bool
7080
{
7181
return true;
@@ -81,4 +91,15 @@ private function isOldChrome(): bool
8191
return getenv('WEB_FIXTURES_BROWSER') === 'chrome'
8292
&& version_compare(getenv('SELENIUM_VERSION') ?: '', '3', '<');
8393
}
94+
95+
private function isOldFirefox(): bool
96+
{
97+
return getenv('WEB_FIXTURES_BROWSER') === 'firefox'
98+
&& version_compare(getenv('SELENIUM_VERSION') ?: '', '3', '<');
99+
}
100+
101+
private function isChromiumBased(): bool
102+
{
103+
return in_array($this->getBrowserName(), ['chrome', 'chromium', 'edge']);
104+
}
84105
}

0 commit comments

Comments
 (0)