diff --git a/src/lib/Browser/Element/BaseElement.php b/src/lib/Browser/Element/BaseElement.php index 7ca8d45c..a00b72c8 100644 --- a/src/lib/Browser/Element/BaseElement.php +++ b/src/lib/Browser/Element/BaseElement.php @@ -17,7 +17,7 @@ abstract class BaseElement implements BaseElementInterface { - protected int $timeout = 1; + protected int $timeout = 3; private ElementFactoryInterface $elementFactory; diff --git a/src/lib/Browser/Page/RedirectLoginPage.php b/src/lib/Browser/Page/RedirectLoginPage.php index 7a1112ba..3a0a8e60 100644 --- a/src/lib/Browser/Page/RedirectLoginPage.php +++ b/src/lib/Browser/Page/RedirectLoginPage.php @@ -8,6 +8,8 @@ namespace Ibexa\Behat\Browser\Page; +use Exception; +use Ibexa\Behat\Browser\Exception\ElementNotFoundException; use Ibexa\Behat\Browser\Locator\CSSLocator; use PHPUnit\Framework\Assert; @@ -25,10 +27,19 @@ public function verifyIsLoaded(): void public function loginSuccessfully($username, $password): void { - parent::loginSuccessfully($username, $password); - $this->getHTMLPage() - ->findAll(new CSSLocator('loginSuccess', '#login-success')) - ->assert()->hasElements(); + for ($attempt = 0; $attempt < 3; ++$attempt) { + try { + parent::loginSuccessfully($username, $password); + $this->getHTMLPage() + ->findAll(new CSSLocator('loginSuccess', '#login-success')) + ->assert()->hasElements(); + + return; + } catch (Exception $e) { + // Retry on failure + } + } + throw new ElementNotFoundException('Login failed after multiple attempts.'); } protected function getRoute(): string diff --git a/tests/lib/Browser/Element/ElementTest.php b/tests/lib/Browser/Element/ElementTest.php index b40ad725..ecad04a7 100644 --- a/tests/lib/Browser/Element/ElementTest.php +++ b/tests/lib/Browser/Element/ElementTest.php @@ -55,7 +55,7 @@ public function testFindElementWhenNotExists(): void $element = $this->createElementWithMinkElement($minkElement); $this->expectException(TimeoutException::class); - $this->expectExceptionMessage("CSS selector 'invalid-id': 'invalid-selector' not found in 1 seconds."); + $this->expectExceptionMessage("CSS selector 'invalid-id': 'invalid-selector' not found in 3 seconds."); $element->find($this->invalidLocator); }