Skip to content

Commit edb5c49

Browse files
authored
Merge pull request #742 from magento-obsessive-owls/PWA-691
PWA-691: Fix Waits In PWA MFTF MagentoPwaWebDriver
2 parents 360beb4 + 821a4d5 commit edb5c49

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,57 @@
1717
*/
1818
class MagentoPwaWebDriver extends MagentoWebDriver
1919
{
20+
/**
21+
* List of known PWA loading masks by selector
22+
*
23+
* Overriding the MagentoWebDriver array to contain applicable PWA locators.
24+
*
25+
* @var array
26+
*/
27+
protected $loadingMasksLocators = [
28+
'//div[contains(@class, "indicator-global-")]',
29+
'//div[contains(@class, "indicator-root-")]',
30+
'//img[contains(@class, "indicator-indicator-")]',
31+
'//span[contains(@class, "indicator-message-")]'
32+
];
33+
2034
/**
2135
* Go to the page.
2236
*
2337
* Overriding the MagentoWebDriver version because it contains 'waitForPageLoad'.
2438
* The AJAX check in 'waitForPageLoad' does NOT work with a PWA.
2539
*
26-
* @param string $page
40+
* @param string $page
41+
* @param integer $timeout
2742
* @throws \Exception
2843
* @return void
2944
*/
30-
public function amOnPage($page)
45+
public function amOnPage($page, $timeout = null)
3146
{
3247
WebDriver::amOnPage($page);
48+
$this->waitForLoadingMaskToDisappear($timeout);
3349
}
3450

3551
/**
3652
* Wait for a PWA Element to NOT be visible using JavaScript.
3753
* Add the WAIT_TIMEOUT variable to your .env file for this action.
3854
*
39-
* @param null $selector
40-
* @param null $timeout
55+
* @param string $selector
56+
* @param integer $timeout
4157
* @throws \Exception
4258
* @return void
4359
*/
4460
public function waitForPwaElementNotVisible($selector, $timeout = null)
4561
{
62+
$timeout = $timeout ?? $this->_getConfig()['pageload_timeout'];
63+
4664
// Determine what type of Selector is used.
4765
// Then use the correct JavaScript to locate the Element.
4866
if (\Codeception\Util\Locator::isXPath($selector)) {
67+
$this->waitForLoadingMaskToDisappear($timeout);
4968
$this->waitForJS("return !document.evaluate(`$selector`, document);", $timeout);
5069
} else {
70+
$this->waitForLoadingMaskToDisappear($timeout);
5171
$this->waitForJS("return !document.querySelector(`$selector`);", $timeout);
5272
}
5373
}
@@ -56,18 +76,22 @@ public function waitForPwaElementNotVisible($selector, $timeout = null)
5676
* Wait for a PWA Element to be visible using JavaScript.
5777
* Add the WAIT_TIMEOUT variable to your .env file for this action.
5878
*
59-
* @param null $selector
60-
* @param null $timeout
79+
* @param string $selector
80+
* @param integer $timeout
6181
* @throws \Exception
6282
* @return void
6383
*/
6484
public function waitForPwaElementVisible($selector, $timeout = null)
6585
{
86+
$timeout = $timeout ?? $this->_getConfig()['pageload_timeout'];
87+
6688
// Determine what type of Selector is used.
6789
// Then use the correct JavaScript to locate the Element.
6890
if (\Codeception\Util\Locator::isXPath($selector)) {
91+
$this->waitForLoadingMaskToDisappear($timeout);
6992
$this->waitForJS("return !!document && !!document.evaluate(`$selector`, document);", $timeout);
7093
} else {
94+
$this->waitForLoadingMaskToDisappear($timeout);
7195
$this->waitForJS("return !!document && !!document.querySelector(`$selector`);", $timeout);
7296
}
7397
}

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class MagentoWebDriver extends WebDriver
6363
*
6464
* @var array
6565
*/
66-
public static $loadingMasksLocators = [
66+
protected $loadingMasksLocators = [
6767
'//div[contains(@class, "loading-mask")]',
6868
'//div[contains(@class, "admin_data-grid-loading-mask")]',
6969
'//div[contains(@class, "admin__data-grid-loading-mask")]',
@@ -439,7 +439,9 @@ public function waitForPageLoad($timeout = null)
439439
*/
440440
public function waitForLoadingMaskToDisappear($timeout = null)
441441
{
442-
foreach (self::$loadingMasksLocators as $maskLocator) {
442+
$timeout = $timeout ?? $this->_getConfig()['pageload_timeout'];
443+
444+
foreach ($this->loadingMasksLocators as $maskLocator) {
443445
// Get count of elements found for looping.
444446
// Elements are NOT useful for interaction, as they cannot be fed to codeception actions.
445447
$loadingMaskElements = $this->_findElements($maskLocator);

0 commit comments

Comments
 (0)