|
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,27 @@ 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 iShouldSee($text) |
| 323 | + { |
| 324 | + $maxAttempts = 3; |
| 325 | + $waitTimeMs = 1000; |
| 326 | + |
| 327 | + for ($attempt = 1; $attempt <= $maxAttempts; $attempt++) { |
| 328 | + try { |
| 329 | + $this->assertSession()->pageTextContains($this->fixStepArgument($text)); |
| 330 | + return; |
| 331 | + } catch (\WebDriver\Exception\StaleElementReference $e) { |
| 332 | + // Handle Selenium stale element exception, retry |
| 333 | + } catch (\Behat\Mink\Exception\ResponseTextException $e) { |
| 334 | + // Handle Mink text assertion failure, retry |
| 335 | + } |
| 336 | + |
| 337 | + usleep($waitTimeMs * 1000); |
| 338 | + } |
| 339 | + |
| 340 | + throw new Exception(sprintf("Text '%s' not found after %d attempts.", $text, $maxAttempts)); |
| 341 | + } |
328 | 342 | }
|
0 commit comments