From ced250917ad6cec266adc198308c15f260b2cc6c Mon Sep 17 00:00:00 2001 From: Christian Sciberras Date: Tue, 25 Nov 2025 19:18:27 +0100 Subject: [PATCH 1/3] Deprecate safePageWait --- tests/Form/GeneralTest.php | 55 ++++++++++++++++------------------- tests/Form/Html5Test.php | 59 ++++++++++++++++++-------------------- tests/TestCase.php | 16 ++--------- 3 files changed, 56 insertions(+), 74 deletions(-) diff --git a/tests/Form/GeneralTest.php b/tests/Form/GeneralTest.php index a55f0fa..77df511 100644 --- a/tests/Form/GeneralTest.php +++ b/tests/Form/GeneralTest.php @@ -48,11 +48,9 @@ public function testBasicForm(): void $page->pressButton('Save'); - if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) { - $this->assertEquals('Anket for Konstantin', $webAssert->elementExists('css', 'h1')->getText()); - $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText()); - $this->assertEquals('Lastname: Kudryashov', $webAssert->elementExists('css', '#last')->getText()); - } + $this->assertEquals('Anket for Konstantin', $webAssert->elementExists('css', 'h1')->getText()); + $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText()); + $this->assertEquals('Lastname: Kudryashov', $webAssert->elementExists('css', '#last')->getText()); } /** @@ -70,11 +68,7 @@ public function testFormSubmitWays(string $submitVia): void $page->pressButton($submitVia); - if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) { - $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText()); - } else { - $this->fail('Form was never submitted'); - } + $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText()); } /** @@ -98,9 +92,7 @@ public function testFormSubmit(): void $webAssert->elementExists('xpath', 'descendant-or-self::form[1]')->submit(); - if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) { - $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText()); - } + $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText()); } public function testFormSubmitWithoutButton(): void @@ -113,9 +105,7 @@ public function testFormSubmitWithoutButton(): void $webAssert->elementExists('xpath', 'descendant-or-self::form[1]')->submit(); - if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) { - $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText()); - } + $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText()); } public function testBasicGetForm(): void @@ -204,8 +194,8 @@ public function testAdvancedForm(): void $button->press(); - if ($this->safePageWait(5000, 'document.getElementsByTagName("title") === "Advanced form save"')) { - $out = <<<'OUT' + $this->assertStringContainsString( + <<<'OUT' array( agreement = `on`, email = `ever.zet@gmail.com`, @@ -218,9 +208,9 @@ public function testAdvancedForm(): void ) some_file.txt 1 uploaded file -OUT; - $this->assertStringContainsString($out, $page->getContent()); - } +OUT, + $page->getContent() + ); } public function testQuoteInValue(): void @@ -245,22 +235,27 @@ public function testQuoteInValue(): void $button->press(); - if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) { - $out = <<<'OUT' + $this->assertThat( + $page->getContent(), + $this->logicalOr( + $this->stringContains( + <<<'OUT' first_name = `Foo "item"`, last_name = `Bar`, -OUT; +OUT + ), + $this->stringContains( // Escaping of double quotes are optional in HTML text nodes. Even though our backend escapes // the quote in the HTML when returning it, browsers may apply only the minimal escaping in // the content they expose to Selenium depending of how they build it (they might serialize - // their DOM again rathet than returning the raw HTTP response content). - $minEscapedOut = <<<'OUT' + // their DOM again rather than returning the raw HTTP response content). + <<<'OUT' first_name = `Foo "item"`, last_name = `Bar`, -OUT; - - $this->assertThat($page->getContent(), $this->logicalOr($this->stringContains($out), $this->stringContains($minEscapedOut))); - } +OUT + ) + ) + ); } public function testMultiInput(): void diff --git a/tests/Form/Html5Test.php b/tests/Form/Html5Test.php index 928a422..ed24ee2 100644 --- a/tests/Form/Html5Test.php +++ b/tests/Form/Html5Test.php @@ -24,14 +24,14 @@ public function testHtml5FormInputAttribute(): void $page->pressButton('Submit in form'); - if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) { - $out = <<<'OUT' + $this->assertStringContainsString( + <<<'OUT' first_name = `John`, last_name = `Doe`, -OUT; - $this->assertStringContainsString($out, $page->getContent()); - $this->assertStringNotContainsString('other_field', $page->getContent()); - } +OUT, + $page->getContent() + ); + $this->assertStringNotContainsString('other_field', $page->getContent()); } public function testHtml5FormRadioAttribute(): void @@ -72,14 +72,14 @@ public function testHtml5FormButtonAttribute(): void $page->pressButton('Submit outside form'); - if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) { - $out = <<<'OUT' + $this->assertStringContainsString( + <<<'OUT' first_name = `John`, last_name = `Doe`, submit_button = `test`, -OUT; - $this->assertStringContainsString($out, $page->getContent()); - } +OUT, + $page->getContent() + ); } public function testHtml5FormOutside(): void @@ -91,13 +91,13 @@ public function testHtml5FormOutside(): void $page->pressButton('Submit separate form'); - if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) { - $out = <<<'OUT' + $this->assertStringContainsString( + <<<'OUT' other_field = `hello`, -OUT; - $this->assertStringContainsString($out, $page->getContent()); - $this->assertStringNotContainsString('first_name', $page->getContent()); - } +OUT, + $page->getContent() + ); + $this->assertStringNotContainsString('first_name', $page->getContent()); } public function testHtml5Types(): void @@ -115,7 +115,8 @@ public function testHtml5Types(): void $page->pressButton('Submit'); - $out = <<<'OUT' + $this->assertStringContainsString( + <<<'OUT' color = `#ff00aa`, date = `1111-11-11`, email = `mink@example.org`, @@ -124,9 +125,9 @@ public function testHtml5Types(): void submit_button = `Submit`, time = `14:12`, url = `https://mink.behat.org/`, -OUT; - - $this->assertStringContainsString($out, $page->getContent()); +OUT, + $page->getContent() + ); } public function testHtml5FormAction(): void @@ -137,10 +138,8 @@ public function testHtml5FormAction(): void $page->fillField('first_name', 'Jimmy'); $page->pressButton('Submit to basic form'); - if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) { - $this->assertStringContainsString('Basic Form Saving', $page->getContent()); - $this->assertStringContainsString('Firstname: Jimmy', $page->getContent()); - } + $this->assertStringContainsString('Basic Form Saving', $page->getContent()); + $this->assertStringContainsString('Firstname: Jimmy', $page->getContent()); } public function testHtml5FormMethod(): void @@ -152,12 +151,10 @@ public function testHtml5FormMethod(): void $page->fillField('last_name', 'Jones'); $page->pressButton('Submit as GET'); - if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) { - $this->assertEquals( - $this->pathTo('advanced_form_post.php') . '?first_name=Jimmy&last_name=Jones', - $this->getSession()->getCurrentUrl() - ); - } + $this->assertEquals( + $this->pathTo('advanced_form_post.php') . '?first_name=Jimmy&last_name=Jones', + $this->getSession()->getCurrentUrl() + ); } /** diff --git a/tests/TestCase.php b/tests/TestCase.php index 374a2c3..32d86ea 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -159,21 +159,11 @@ protected function pathTo($path) } /** - * Waits for a condition to be true, considering than it is successful for drivers not supporting wait(). - * - * @param int $time - * @param string $condition A JS condition to evaluate - * - * @return bool - * - * @see \Behat\Mink\Session::wait() + * @deprecated To be removed since drivers are should wait for page navigation automatically and meanwhile tests + * shouldn't try fixing it. */ protected function safePageWait($time, $condition) { - try { - return $this->getSession()->wait($time, $condition); - } catch (UnsupportedDriverActionException $e) { - return true; - } + return true; } } From c14f1089daabdf3799b241c4d0dc0f76d18624cb Mon Sep 17 00:00:00 2001 From: Christian Sciberras Date: Tue, 25 Nov 2025 19:23:46 +0100 Subject: [PATCH 2/3] Fix SA issues --- tests/TestCase.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 32d86ea..e149e7a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,6 @@ namespace Behat\Mink\Tests\Driver; use Behat\Mink\Element\NodeElement; -use Behat\Mink\Exception\UnsupportedDriverActionException; use Behat\Mink\Mink; use Behat\Mink\Session; use Behat\Mink\WebAssert; @@ -159,6 +158,11 @@ protected function pathTo($path) } /** + * @param int $time + * @param string $condition + * + * @return bool + * * @deprecated To be removed since drivers are should wait for page navigation automatically and meanwhile tests * shouldn't try fixing it. */ From faa830e904bc93f0712233747940ddaaa9633bcd Mon Sep 17 00:00:00 2001 From: Christian Sciberras Date: Thu, 27 Nov 2025 22:12:09 +0100 Subject: [PATCH 3/3] CR fix --- tests/TestCase.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/TestCase.php b/tests/TestCase.php index e149e7a..31dd872 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -168,6 +168,11 @@ protected function pathTo($path) */ protected function safePageWait($time, $condition) { + @trigger_error( + sprintf('The method %s is deprecated: drivers should wait for page navigation automatically', __METHOD__), + E_USER_DEPRECATED + ); + return true; } }