Skip to content

Commit d9eceeb

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

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
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 |

tests/features/managing-campaigns/newcampaign.feature

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ Feature: Create new campaign
99
Given I follow "Campaigns"
1010
Given I follow "Send a campaign"
1111
Given I follow "Start a new campaign"
12-
Then I should see "Campaign subject"
12+
Then I must see "Campaign subject"
1313
When I fill in "subject" with "This is a test subject"
1414
And I fill in "fromfield" with "From me me@mydomain.com"
1515
And I fill in "sendmethod" with "inputhere"
1616
And I fill in "message" with "This is the Content of the Campaign"
1717
And I fill in "footer" with "This is the Footer of the campaign"
1818
And I fill in "campaigntitle" with "This is the Title of the Campaign"
1919
And I press "Save and continue editing"
20-
Then I should see "This is the Content of the Campaign"
20+
Then I must see "This is the Content of the Campaign"
2121
When I follow "Scheduling"
22-
Then I should see "Embargoed Until"
22+
Then I must see "Embargoed Until"
2323
When I follow "Lists"
24-
Then I should see "Please select the lists you want to send your campaign to"
25-
And I should see "All Lists"
24+
Then I must see "Please select the lists you want to send your campaign to"
25+
And I must see "All Lists"
2626
When I check "targetlist[all]"
2727
And I press "Save and continue editing"
28-
Then I should see "selected"
28+
Then I must see "selected"
2929
When I follow "Finish"
3030
And I press "send"
31-
Then I should see "Campaign queued"
31+
Then I must see "Campaign queued"
3232

3333
# Switch to using a scenario outline that tests subaccounts also
3434
Scenario: Select a list to send the campaign to
@@ -38,7 +38,7 @@ Feature: Create new campaign
3838
And I follow "Start a new campaign"
3939
When I follow "Lists"
4040
# Try with and without the colon
41-
Then I should see "Please select the lists you want to send your campaign to:"
41+
Then I must see "Please select the lists you want to send your campaign to:"
4242
And the "targetlist[all]" checkbox should not be checked
4343
And the "targetlist[allactive]" checkbox should not be checked
4444

0 commit comments

Comments
 (0)