diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php index 9b75cb10d..272f4206d 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php @@ -17,37 +17,57 @@ */ class MagentoPwaWebDriver extends MagentoWebDriver { + /** + * List of known PWA loading masks by selector + * + * Overriding the MagentoWebDriver array to contain applicable PWA locators. + * + * @var array + */ + protected $loadingMasksLocators = [ + '//div[contains(@class, "indicator-global-")]', + '//div[contains(@class, "indicator-root-")]', + '//img[contains(@class, "indicator-indicator-")]', + '//span[contains(@class, "indicator-message-")]' + ]; + /** * Go to the page. * * Overriding the MagentoWebDriver version because it contains 'waitForPageLoad'. * The AJAX check in 'waitForPageLoad' does NOT work with a PWA. * - * @param string $page + * @param string $page + * @param integer $timeout * @throws \Exception * @return void */ - public function amOnPage($page) + public function amOnPage($page, $timeout = null) { WebDriver::amOnPage($page); + $this->waitForLoadingMaskToDisappear($timeout); } /** * Wait for a PWA Element to NOT be visible using JavaScript. * Add the WAIT_TIMEOUT variable to your .env file for this action. * - * @param null $selector - * @param null $timeout + * @param string $selector + * @param integer $timeout * @throws \Exception * @return void */ public function waitForPwaElementNotVisible($selector, $timeout = null) { + $timeout = $timeout ?? $this->_getConfig()['pageload_timeout']; + // Determine what type of Selector is used. // Then use the correct JavaScript to locate the Element. if (\Codeception\Util\Locator::isXPath($selector)) { + $this->waitForLoadingMaskToDisappear($timeout); $this->waitForJS("return !document.evaluate(`$selector`, document);", $timeout); } else { + $this->waitForLoadingMaskToDisappear($timeout); $this->waitForJS("return !document.querySelector(`$selector`);", $timeout); } } @@ -56,18 +76,22 @@ public function waitForPwaElementNotVisible($selector, $timeout = null) * Wait for a PWA Element to be visible using JavaScript. * Add the WAIT_TIMEOUT variable to your .env file for this action. * - * @param null $selector - * @param null $timeout + * @param string $selector + * @param integer $timeout * @throws \Exception * @return void */ public function waitForPwaElementVisible($selector, $timeout = null) { + $timeout = $timeout ?? $this->_getConfig()['pageload_timeout']; + // Determine what type of Selector is used. // Then use the correct JavaScript to locate the Element. if (\Codeception\Util\Locator::isXPath($selector)) { + $this->waitForLoadingMaskToDisappear($timeout); $this->waitForJS("return !!document && !!document.evaluate(`$selector`, document);", $timeout); } else { + $this->waitForLoadingMaskToDisappear($timeout); $this->waitForJS("return !!document && !!document.querySelector(`$selector`);", $timeout); } } diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index 984881e4e..2f4745df1 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -63,7 +63,7 @@ class MagentoWebDriver extends WebDriver * * @var array */ - public static $loadingMasksLocators = [ + protected $loadingMasksLocators = [ '//div[contains(@class, "loading-mask")]', '//div[contains(@class, "admin_data-grid-loading-mask")]', '//div[contains(@class, "admin__data-grid-loading-mask")]', @@ -439,7 +439,9 @@ public function waitForPageLoad($timeout = null) */ public function waitForLoadingMaskToDisappear($timeout = null) { - foreach (self::$loadingMasksLocators as $maskLocator) { + $timeout = $timeout ?? $this->_getConfig()['pageload_timeout']; + + foreach ($this->loadingMasksLocators as $maskLocator) { // Get count of elements found for looping. // Elements are NOT useful for interaction, as they cannot be fed to codeception actions. $loadingMaskElements = $this->_findElements($maskLocator);