Skip to content

Commit 302d7d7

Browse files
HP-2335 Enhance exception handling to ensure code continues running smoothly if there are unexpected issues. (#299)
* HP-2335 Enhance exception handling to ensure code continues running smoothly if there are unexpected issues. * HP-2335 modernized WaitHelper class
1 parent 0c56545 commit 302d7d7

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

tests/_support/Helper/WaitHelper.php

+39-5
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,59 @@
1010

1111
namespace hipanel\tests\_support\Helper;
1212

13+
use Codeception\TestInterface;
14+
1315
class WaitHelper extends \Codeception\Module
1416
{
17+
private $webDriver = null;
18+
private $webDriverModule = null;
19+
1520
/**
1621
* @var int Default delay to wait while page updating
1722
*/
18-
protected int $defaultDelay = 5;
23+
protected int $defaultDelay = 1;
24+
25+
public function _before(TestInterface $test)
26+
{
27+
if (!$this->hasModule('WebDriver') && !$this->hasModule('Selenium2')) {
28+
throw new \Exception('PageWait uses the WebDriver. Please be sure that this module is activated.');
29+
}
30+
31+
// Use WebDriver
32+
if ($this->hasModule('WebDriver')) {
33+
$this->webDriverModule = $this->getModule('WebDriver');
34+
$this->webDriver = $this->webDriverModule->webDriver;
35+
}
36+
}
1937

2038
/**
2139
* @param int $timeOut
2240
* @throws \Codeception\Exception\ModuleException
2341
*/
24-
public function waitForPageUpdate($timeOut = 180): void
42+
public function waitForPageUpdate(int $timeOut = 180): void
2543
{
26-
$I = $this->getModule('WebDriver');
44+
$this->webDriverModule = $this->getModule('WebDriver');
2745

2846
try {
29-
$I->waitForJS('return $.active == 0;', $timeOut);
47+
$this->webDriverModule->waitForJS('return $.active == 0;', $timeOut);
48+
49+
$this->webDriverModule->debug('JS check passed: no active requests.');
3050
} catch (\Facebook\WebDriver\Exception\JavascriptErrorException $exception) {
31-
$I->wait($this->defaultDelay);
51+
$this->webDriverModule->wait($this->defaultDelay);
52+
53+
$this->webDriverModule->debug('JS Error: ' . $exception->getMessage());
3254
}
3355
}
56+
57+
public function waitPageLoad($timeout = 10)
58+
{
59+
$this->webDriverModule->waitForJs('return document.readyState == "complete"', $timeout);
60+
$this->waitAjaxLoad($timeout);
61+
}
62+
63+
public function waitAjaxLoad($timeout = 10)
64+
{
65+
$this->webDriverModule->waitForJS('return !!window.jQuery && window.jQuery.active == 0;', $timeout);
66+
$this->webDriverModule->wait($this->defaultDelay);
67+
}
3468
}

tests/_support/Page/IndexPage.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ public function setAdvancedFilter(TestableInput $filter, string $value): void
239239
$this->gridView->setAdvancedFilter($filter, $value);
240240
}
241241

242-
public function getRowNumberInColumnByValue(string $columnName, string $vaule): int
242+
public function getRowNumberInColumnByValue(string $columnName, string $value): int
243243
{
244-
return $this->gridView->getRowNumberInColumnByValue($columnName, $vaule);
244+
return $this->gridView->getRowNumberInColumnByValue($columnName, $value);
245245
}
246246

247247
public function getColumnNumber(string $columnName): int

0 commit comments

Comments
 (0)