Skip to content

Commit 3fb665c

Browse files
committed
ISSUE-338: retry test
1 parent e32fe9b commit 3fb665c

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

tests/features/bootstrap/FeatureContext.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
<?php
22

3-
use Behat\Behat\Context\Context;
43

54
use Behat\Mink\Exception\ExpectationException;
65
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-
//
156

167
/**
178
* Features context.
@@ -107,7 +98,7 @@ public function spins($closure, $tries = 10)
10798
$closure();
10899

109100
return;
110-
} catch (\Exception $e) {
101+
} catch (Exception $e) {
111102
if ($i == $tries) {
112103
throw $e;
113104
}
@@ -179,7 +170,7 @@ public function isLoggedIn($throwsException = false)
179170
{
180171
$retVal = $this->token != null;
181172
if(!$retVal && $throwsException){
182-
throw new \Exception('Not logged in yet');
173+
throw new Exception('Not logged in yet');
183174
}
184175
return $retVal;
185176
}
@@ -325,4 +316,27 @@ public function iConfirmThePopup()
325316
$this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
326317
}
327318

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+
}
328342
}

tests/features/getting-started/menu.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Feature: Navigate the app using the menu
77

88
Scenario Outline: Use main menu navigation links
99
Given I have logged in as an administrator
10-
Then I should see "<Pagename>"
10+
Then I must see "<Pagename>"
1111
Examples:
1212
| Pagename |
1313
| dashboard |

0 commit comments

Comments
 (0)