From e2323a2e93ccebc88a6fca48c3fffc84064d28cb Mon Sep 17 00:00:00 2001 From: John S Date: Wed, 12 Dec 2018 15:13:34 -0600 Subject: [PATCH 1/5] magento-research/pwa-tests#MQE-1382-WaitForReactPageLoad - Adding a new action for waitForReactPageLoad to the schema. - Adding basic structure for the new action to the MagentoWebDriver. --- .../Module/MagentoWebDriver.php | 15 +++++++++++++++ .../Test/etc/Actions/waitActions.xsd | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index 452a40bde..a5641adcf 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -379,6 +379,21 @@ public function waitForPageLoad($timeout = null) $this->waitForLoadingMaskToDisappear($timeout); } + /** + * Wait for all React JavaScript to finish executing. + * + * @param integer $timeout + * @throws \Exception + * @return void + */ + public function waitForReactPageLoad($timeout = null) + { + $timeout = $timeout ?? $this->_getConfig()['pageload_timeout']; + + $this->waitForJS('return (!!Object.keys(document).filter(prop => /^_reactListenersID/.test(prop)).length) || (document.querySelector("[data-reactroot]") && Object.keys(rootEl).some(prop => /^__reactInternalInstance/.test(prop)));', $timeout); + $this->waitForJS("return document.readyState == 'complete';", $timeout); + } + /** * Wait for all visible loading masks to disappear. Gets all elements by mask selector, then loops over them. * diff --git a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd index 5350d9d3e..ad751d9e1 100644 --- a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd +++ b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd @@ -20,6 +20,7 @@ + @@ -176,6 +177,20 @@ + + + + Waits up to given time for React page to have finished loading.. + + + + + + + + + + From d2312ef8c06100b2199f591d388279eac70e5d80 Mon Sep 17 00:00:00 2001 From: John S Date: Tue, 8 Jan 2019 14:23:46 -0600 Subject: [PATCH 2/5] magento-research/pwa-tests#MQE-1382-WaitForReactPageLoad - Switched gears with this attempt, created a waitForElementVisible action instead of a waitForReactPageLoad action. - Adding new action, DI updates and Actions updates. --- etc/di.xml | 2 +- .../Module/MagentoWebDriver.php | 37 ++++++++++++++++--- .../Test/etc/Actions/waitActions.xsd | 25 +++++++++++-- .../Util/TestGenerator.php | 2 + 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/etc/di.xml b/etc/di.xml index 60faed3a0..bf002da7b 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -8,7 +8,7 @@ + ]> diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index a5641adcf..a9961bd7d 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -380,18 +380,45 @@ public function waitForPageLoad($timeout = null) } /** - * Wait for all React JavaScript to finish executing. + * Wait for an Element to NOT be visible using JavaScript. * - * @param integer $timeout + * @param null $selector + * @param null $timeout * @throws \Exception * @return void */ - public function waitForReactPageLoad($timeout = null) + public function waitForJsElementNotVisible($selector, $timeout = null) { $timeout = $timeout ?? $this->_getConfig()['pageload_timeout']; - $this->waitForJS('return (!!Object.keys(document).filter(prop => /^_reactListenersID/.test(prop)).length) || (document.querySelector("[data-reactroot]") && Object.keys(rootEl).some(prop => /^__reactInternalInstance/.test(prop)));', $timeout); - $this->waitForJS("return document.readyState == 'complete';", $timeout); + // Determine what type of Selector is used. + // Then use the correct JavaScript to locate the Element. + if (\Codeception\Util\Locator::isXPath($selector)) { + $this->waitForJS("return !document.evaluate(`$selector`, document);", $timeout); + } else { + $this->waitForJS("return !document.querySelector(`$selector`);", $timeout); + } + } + + /** + * Wait for an Element to be visible using JavaScript. + * + * @param null $selector + * @param null $timeout + * @throws \Exception + * @return void + */ + public function waitForJsElementVisible($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->waitForJS("return !!document && !!document.evaluate(`$selector`, document);", $timeout); + } else { + $this->waitForJS("return !!document && !!document.querySelector(`$selector`);", $timeout); + } } /** diff --git a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd index ad751d9e1..f8aebcd49 100644 --- a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd +++ b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd @@ -20,7 +20,8 @@ - + + @@ -166,7 +167,7 @@ - Waits up to given time for page to have finished loading.. + Waits up to given time for page to have finished loading. @@ -177,15 +178,31 @@ - + - Waits up to given time for React page to have finished loading.. + Waits up to given time for a React Element to disappear from the screen using JavaScript. + + + + + + + + + + Waits up to given time for a React Element to appear on the screen using JavaScript. + + + + + + diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 4113f96ee..643a2efcf 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -1045,6 +1045,8 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato case "waitForElement": case "waitForElementVisible": case "waitForElementNotVisible": + case "waitForJsElementVisible": + case "waitForJsElementNotVisible": $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $time); break; case "waitForPageLoad": From ea2a2c75e9a2d6dc1e20185bfa2b44a000184913 Mon Sep 17 00:00:00 2001 From: John S Date: Wed, 9 Jan 2019 10:11:38 -0600 Subject: [PATCH 3/5] magento-research/pwa-tests#MQE-1382-WaitForReactPageLoad - Renaming the new Actions to make it clear what they are for. Replaced "Js" with "Pwa". --- etc/di.xml | 2 +- .../Module/MagentoWebDriver.php | 8 ++++---- .../Test/etc/Actions/waitActions.xsd | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/etc/di.xml b/etc/di.xml index bf002da7b..3e6313bf3 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -8,7 +8,7 @@ + ]> diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index a9961bd7d..d9f761896 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -380,14 +380,14 @@ public function waitForPageLoad($timeout = null) } /** - * Wait for an Element to NOT be visible using JavaScript. + * Wait for a PWA Element to NOT be visible using JavaScript. * * @param null $selector * @param null $timeout * @throws \Exception * @return void */ - public function waitForJsElementNotVisible($selector, $timeout = null) + public function waitForPwaElementNotVisible($selector, $timeout = null) { $timeout = $timeout ?? $this->_getConfig()['pageload_timeout']; @@ -401,14 +401,14 @@ public function waitForJsElementNotVisible($selector, $timeout = null) } /** - * Wait for an Element to be visible using JavaScript. + * Wait for a PWA Element to be visible using JavaScript. * * @param null $selector * @param null $timeout * @throws \Exception * @return void */ - public function waitForJsElementVisible($selector, $timeout = null) + public function waitForPwaElementVisible($selector, $timeout = null) { $timeout = $timeout ?? $this->_getConfig()['pageload_timeout']; diff --git a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd index f8aebcd49..70b8201a1 100644 --- a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd +++ b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd @@ -20,8 +20,8 @@ - - + + @@ -178,10 +178,10 @@ - + - Waits up to given time for a React Element to disappear from the screen using JavaScript. + Waits up to given time for a PWA Element to disappear from the screen using JavaScript. @@ -193,10 +193,10 @@ - + - Waits up to given time for a React Element to appear on the screen using JavaScript. + Waits up to given time for a PWA Element to appear on the screen using JavaScript. From 149332a0c8c89700181d89f0616c71b652e16447 Mon Sep 17 00:00:00 2001 From: John S Date: Wed, 9 Jan 2019 13:35:02 -0600 Subject: [PATCH 4/5] magento-research/pwa-tests#MQE-1382-WaitForReactPageLoad - Updating the action name in the Generator file. --- src/Magento/FunctionalTestingFramework/Util/TestGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 643a2efcf..abc62eb20 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -1045,8 +1045,8 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato case "waitForElement": case "waitForElementVisible": case "waitForElementNotVisible": - case "waitForJsElementVisible": - case "waitForJsElementNotVisible": + case "waitForPwaElementVisible": + case "waitForPwaElementNotVisible": $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $time); break; case "waitForPageLoad": From cbe914b68f1f0ff23ec0c2260d59ca30517c5537 Mon Sep 17 00:00:00 2001 From: John S Date: Thu, 10 Jan 2019 10:35:56 -0600 Subject: [PATCH 5/5] magento-research/pwa-tests#MQE-1382-WaitForReactPageLoad - Created a separate Class for the custom PWA actions. - Removed the custom PWA actions from MagentoWebDriver. --- .../Module/MagentoPwaWebDriver.php | 59 +++++++++++++++++++ .../Module/MagentoWebDriver.php | 42 ------------- 2 files changed, 59 insertions(+), 42 deletions(-) create mode 100644 src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php new file mode 100644 index 000000000..98b13fe90 --- /dev/null +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoPwaWebDriver.php @@ -0,0 +1,59 @@ +_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->waitForJS("return !document.evaluate(`$selector`, document);", $timeout); + } else { + $this->waitForJS("return !document.querySelector(`$selector`);", $timeout); + } + } + + /** + * Wait for a PWA Element to be visible using JavaScript. + * + * @param null $selector + * @param null $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->waitForJS("return !!document && !!document.evaluate(`$selector`, document);", $timeout); + } else { + $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 386ca2344..a15ed757e 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -379,48 +379,6 @@ public function waitForPageLoad($timeout = null) $this->waitForLoadingMaskToDisappear($timeout); } - /** - * Wait for a PWA Element to NOT be visible using JavaScript. - * - * @param null $selector - * @param null $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->waitForJS("return !document.evaluate(`$selector`, document);", $timeout); - } else { - $this->waitForJS("return !document.querySelector(`$selector`);", $timeout); - } - } - - /** - * Wait for a PWA Element to be visible using JavaScript. - * - * @param null $selector - * @param null $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->waitForJS("return !!document && !!document.evaluate(`$selector`, document);", $timeout); - } else { - $this->waitForJS("return !!document && !!document.querySelector(`$selector`);", $timeout); - } - } - /** * Wait for all visible loading masks to disappear. Gets all elements by mask selector, then loops over them. *