From d3d5b2864bfed03e2b344a4a17690d2dade7a9d0 Mon Sep 17 00:00:00 2001 From: David Haecker Date: Tue, 16 Jun 2020 11:27:27 -0500 Subject: [PATCH 1/5] 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 --- .../Module/MagentoPwaWebDriver.php | 24 ++++++++++++++++++- .../Module/MagentoWebDriver.php | 6 +++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php index 9b75cb10d..abfbaf751 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php @@ -17,6 +17,18 @@ */ 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-3ae")]', + '//div[contains(@class, "indicator-message-2he")]' + ]; + /** * Go to the page. * @@ -24,12 +36,14 @@ class MagentoPwaWebDriver extends MagentoWebDriver * The AJAX check in 'waitForPageLoad' does NOT work with a PWA. * * @param string $page + * @param null $timeout * @throws \Exception * @return void */ - public function amOnPage($page) + public function amOnPage($page, $timeout = null) { WebDriver::amOnPage($page); + $this->waitForLoadingMaskToDisappear($timeout); } /** @@ -43,11 +57,15 @@ public function amOnPage($page) */ 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); } } @@ -63,11 +81,15 @@ public function waitForPwaElementNotVisible($selector, $timeout = null) */ 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); From 15b9b2955f046e5e7d5e4066523825fff66c2f77 Mon Sep 17 00:00:00 2001 From: David Haecker Date: Tue, 16 Jun 2020 12:32:16 -0500 Subject: [PATCH 2/5] PWA-691: Fix Waits In PWA MFTF MagentoPwaWebDriver - Adding locators to wait for in PWA webdriver --- .../FunctionalTestingFramework/Module/MagentoPwaWebDriver.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php index abfbaf751..9d6031e18 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php @@ -26,6 +26,8 @@ class MagentoPwaWebDriver extends MagentoWebDriver */ protected $loadingMasksLocators = [ '//div[contains(@class, "indicator-global-3ae")]', + '//div[contains(@class, "indicator-root-3J-")]', + '//div[contains(@class, "indicator-indicator-JHR")]', '//div[contains(@class, "indicator-message-2he")]' ]; From c502e467db838d4d13eadcda887ae8e63b672cc2 Mon Sep 17 00:00:00 2001 From: David Haecker Date: Tue, 16 Jun 2020 12:59:30 -0500 Subject: [PATCH 3/5] PWA-691: Fix Waits In PWA MFTF MagentoPwaWebDriver - Fixing locators to wait for in PWA webdriver --- .../Module/MagentoPwaWebDriver.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php index 9d6031e18..d16249d98 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php @@ -25,10 +25,10 @@ class MagentoPwaWebDriver extends MagentoWebDriver * @var array */ protected $loadingMasksLocators = [ - '//div[contains(@class, "indicator-global-3ae")]', - '//div[contains(@class, "indicator-root-3J-")]', - '//div[contains(@class, "indicator-indicator-JHR")]', - '//div[contains(@class, "indicator-message-2he")]' + '//div[contains(@class, "indicator-global-")]', + '//div[contains(@class, "indicator-root-")]', + '//img[contains(@class, "indicator-indicator-")]', + '//span[contains(@class, "indicator-message-")]' ]; /** From fb3da40f264318fd54ee9fb48153c8b46ae5814a Mon Sep 17 00:00:00 2001 From: David Haecker Date: Tue, 16 Jun 2020 15:35:57 -0500 Subject: [PATCH 4/5] PWA-691: Fix Waits In PWA MFTF MagentoPwaWebDriver - Fixing parameter types --- .../Module/MagentoPwaWebDriver.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php index d16249d98..46860b59d 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php @@ -38,7 +38,7 @@ class MagentoPwaWebDriver extends MagentoWebDriver * The AJAX check in 'waitForPageLoad' does NOT work with a PWA. * * @param string $page - * @param null $timeout + * @param integer $timeout * @throws \Exception * @return void */ @@ -52,8 +52,8 @@ public function amOnPage($page, $timeout = null) * 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 */ @@ -76,8 +76,8 @@ 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 */ From 72ffec286ad431c54601ff96cdd7d95e1484ff13 Mon Sep 17 00:00:00 2001 From: David Haecker Date: Tue, 16 Jun 2020 18:37:40 -0500 Subject: [PATCH 5/5] PWA-691: Fix Waits In PWA MFTF MagentoPwaWebDriver - Fixing static test failures --- .../Module/MagentoPwaWebDriver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php index 46860b59d..272f4206d 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php @@ -37,7 +37,7 @@ class MagentoPwaWebDriver extends MagentoWebDriver * 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 @@ -52,7 +52,7 @@ public function amOnPage($page, $timeout = null) * Wait for a PWA Element to NOT be visible using JavaScript. * Add the WAIT_TIMEOUT variable to your .env file for this action. * - * @param string $selector + * @param string $selector * @param integer $timeout * @throws \Exception * @return void @@ -76,7 +76,7 @@ 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 string $selector + * @param string $selector * @param integer $timeout * @throws \Exception * @return void