Skip to content

Commit

Permalink
retry on random login failure
Browse files Browse the repository at this point in the history
  • Loading branch information
micszo committed Feb 14, 2025
1 parent c6f8d02 commit ce5078e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/lib/Browser/Page/RedirectLoginPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

namespace Ibexa\Behat\Browser\Page;

use Exception;
use Ibexa\Behat\Browser\Locator\CSSLocator;
use PHPUnit\Framework\Assert;
use Ibexa\Behat\Browser\Exception\ElementNotFoundException;

class RedirectLoginPage extends LoginPage
{
Expand All @@ -25,10 +27,18 @@ 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
Expand Down

0 comments on commit ce5078e

Please sign in to comment.