Skip to content

Commit d3d5b28

Browse files
committed
PWA-691: Fix Waits In PWA MFTF MagentoPwaWebDriver
- Adding locators to wait for in PWA webdriver - Updating Magento webdriver to correctly use loading icon locators - Updating Magento webdriver to use pageload_timeout
1 parent ec9c4d3 commit d3d5b28

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

Diff for: src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,33 @@
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-3ae")]',
29+
'//div[contains(@class, "indicator-message-2he")]'
30+
];
31+
2032
/**
2133
* Go to the page.
2234
*
2335
* Overriding the MagentoWebDriver version because it contains 'waitForPageLoad'.
2436
* The AJAX check in 'waitForPageLoad' does NOT work with a PWA.
2537
*
2638
* @param string $page
39+
* @param null $timeout
2740
* @throws \Exception
2841
* @return void
2942
*/
30-
public function amOnPage($page)
43+
public function amOnPage($page, $timeout = null)
3144
{
3245
WebDriver::amOnPage($page);
46+
$this->waitForLoadingMaskToDisappear($timeout);
3347
}
3448

3549
/**
@@ -43,11 +57,15 @@ public function amOnPage($page)
4357
*/
4458
public function waitForPwaElementNotVisible($selector, $timeout = null)
4559
{
60+
$timeout = $timeout ?? $this->_getConfig()['pageload_timeout'];
61+
4662
// Determine what type of Selector is used.
4763
// Then use the correct JavaScript to locate the Element.
4864
if (\Codeception\Util\Locator::isXPath($selector)) {
65+
$this->waitForLoadingMaskToDisappear($timeout);
4966
$this->waitForJS("return !document.evaluate(`$selector`, document);", $timeout);
5067
} else {
68+
$this->waitForLoadingMaskToDisappear($timeout);
5169
$this->waitForJS("return !document.querySelector(`$selector`);", $timeout);
5270
}
5371
}
@@ -63,11 +81,15 @@ public function waitForPwaElementNotVisible($selector, $timeout = null)
6381
*/
6482
public function waitForPwaElementVisible($selector, $timeout = null)
6583
{
84+
$timeout = $timeout ?? $this->_getConfig()['pageload_timeout'];
85+
6686
// Determine what type of Selector is used.
6787
// Then use the correct JavaScript to locate the Element.
6888
if (\Codeception\Util\Locator::isXPath($selector)) {
89+
$this->waitForLoadingMaskToDisappear($timeout);
6990
$this->waitForJS("return !!document && !!document.evaluate(`$selector`, document);", $timeout);
7091
} else {
92+
$this->waitForLoadingMaskToDisappear($timeout);
7193
$this->waitForJS("return !!document && !!document.querySelector(`$selector`);", $timeout);
7294
}
7395
}

Diff for: src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

+4-2
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)