|
1 | 1 | <?php |
2 | 2 |
|
3 | | -use Behat\Behat\Context\Context; |
4 | 3 |
|
5 | 4 | use Behat\Mink\Exception\ExpectationException; |
6 | 5 | use Behat\MinkExtension\Context\MinkContext; |
7 | | -#use Behat\MinkExtension\Context\RawMinkContext; |
8 | | - |
9 | | -// |
10 | | -// Require 3rd-party libraries here: |
11 | | -// |
12 | | -// require_once 'PHPUnit/Autoload.php'; |
13 | | -// require_once 'PHPUnit/Framework/Assert/Functions.php'; |
14 | | -// |
15 | 6 |
|
16 | 7 | /** |
17 | 8 | * Features context. |
@@ -107,7 +98,7 @@ public function spins($closure, $tries = 10) |
107 | 98 | $closure(); |
108 | 99 |
|
109 | 100 | return; |
110 | | - } catch (\Exception $e) { |
| 101 | + } catch (Exception $e) { |
111 | 102 | if ($i == $tries) { |
112 | 103 | throw $e; |
113 | 104 | } |
@@ -179,7 +170,7 @@ public function isLoggedIn($throwsException = false) |
179 | 170 | { |
180 | 171 | $retVal = $this->token != null; |
181 | 172 | if(!$retVal && $throwsException){ |
182 | | - throw new \Exception('Not logged in yet'); |
| 173 | + throw new Exception('Not logged in yet'); |
183 | 174 | } |
184 | 175 | return $retVal; |
185 | 176 | } |
@@ -325,4 +316,28 @@ public function iConfirmThePopup() |
325 | 316 | $this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); |
326 | 317 | } |
327 | 318 |
|
| 319 | + /** |
| 320 | + * @Then I must see :text |
| 321 | + */ |
| 322 | + public function iMustSee($text) |
| 323 | + { |
| 324 | + $maxAttempts = 3; |
| 325 | + $waitTimeMs = 1000; |
| 326 | + $this->getSession()->wait(5000, "document.readyState === 'complete'"); |
| 327 | + |
| 328 | + for ($attempt = 1; $attempt <= $maxAttempts; $attempt++) { |
| 329 | + try { |
| 330 | + $this->assertSession()->pageTextContains($this->fixStepArgument($text)); |
| 331 | + return; |
| 332 | + } catch (\WebDriver\Exception\StaleElementReference $e) { |
| 333 | + // Handle Selenium stale element exception, retry |
| 334 | + } catch (\Behat\Mink\Exception\ResponseTextException $e) { |
| 335 | + // Handle Mink text assertion failure, retry |
| 336 | + } |
| 337 | + |
| 338 | + usleep($waitTimeMs * 1000); |
| 339 | + } |
| 340 | + |
| 341 | + throw new Exception(sprintf("Text '%s' not found after %d attempts.", $text, $maxAttempts)); |
| 342 | + } |
328 | 343 | } |
0 commit comments