Skip to content

Commit d2312ef

Browse files
committed
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.
1 parent e2323a2 commit d2312ef

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<!-- Entity value gets replaced in Dom.php before reading $xml -->
1010
<!DOCTYPE config [
11-
<!ENTITY commonTestActions "acceptPopup|actionGroup|amOnPage|amOnUrl|amOnSubdomain|appendField|assertArrayIsSorted|assertArraySubset|assertElementContainsAttribute|attachFile|cancelPopup|checkOption|clearField|click|clickWithLeftButton|clickWithRightButton|closeAdminNotification|closeTab|comment|conditionalClick|createData|deleteData|updateData|getData|dontSee|dontSeeJsError|dontSeeCheckboxIsChecked|dontSeeCookie|dontSeeCurrentUrlEquals|dontSeeCurrentUrlMatches|dontSeeElement|dontSeeElementInDOM|dontSeeInCurrentUrl|dontSeeInField|dontSeeInFormFields|dontSeeInPageSource|dontSeeInSource|dontSeeInTitle|dontSeeLink|dontSeeOptionIsSelected|doubleClick|dragAndDrop|entity|executeJS|executeInSelenium|fillField|formatMoney|generateDate|grabAttributeFrom|grabCookie|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|loadSessionSnapshot|loginAsAdmin|magentoCLI|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|mSetLocale|mResetLocale|openNewTab|pauseExecution|parseFloat|performOn|pressKey|reloadPage|resetCookie|submitForm|resizeWindow|saveSessionSnapshot|scrollTo|scrollToTopOfPage|searchAndMultiSelectOption|see|seeCheckboxIsChecked|seeCookie|seeCurrentUrlEquals|seeCurrentUrlMatches|seeElement|seeElementInDOM|seeInCurrentUrl|seeInField|seeInFormFields|seeInPageSource|seeInPopup|seeInSource|seeInTitle|seeLink|seeNumberOfElements|seeOptionIsSelected|selectOption|setCookie|submitForm|switchToIFrame|switchToNextTab|switchToPreviousTab|switchToWindow|typeInPopup|uncheckOption|unselectOption|wait|waitForAjaxLoad|waitForElement|waitForElementChange|waitForElementNotVisible|waitForElementVisible|waitForJS|waitForLoadingMaskToDisappear|waitForPageLoad|waitForText|assertArrayHasKey|assertArrayNotHasKey|assertArraySubset|assertContains|assertCount|assertEmpty|assertEquals|assertFalse|assertFileExists|assertFileNotExists|assertGreaterOrEquals|assertGreaterThan|assertGreaterThanOrEqual|assertInstanceOf|assertInternalType|assertIsEmpty|assertLessOrEquals|assertLessThan|assertLessThanOrEqual|assertNotContains|assertNotEmpty|assertNotEquals|assertNotInstanceOf|assertNotNull|assertNotRegExp|assertNotSame|assertNull|assertRegExp|assertSame|assertStringStartsNotWith|assertStringStartsWith|assertTrue|expectException|fail|dontSeeFullUrlEquals|dontSee|dontSeeFullUrlMatches|dontSeeInFullUrl|seeFullUrlEquals|seeFullUrlMatches|seeInFullUrl|grabFromFullUrl">
11+
<!ENTITY commonTestActions "acceptPopup|actionGroup|amOnPage|amOnUrl|amOnSubdomain|appendField|assertArrayIsSorted|assertArraySubset|assertElementContainsAttribute|attachFile|cancelPopup|checkOption|clearField|click|clickWithLeftButton|clickWithRightButton|closeAdminNotification|closeTab|comment|conditionalClick|createData|deleteData|updateData|getData|dontSee|dontSeeJsError|dontSeeCheckboxIsChecked|dontSeeCookie|dontSeeCurrentUrlEquals|dontSeeCurrentUrlMatches|dontSeeElement|dontSeeElementInDOM|dontSeeInCurrentUrl|dontSeeInField|dontSeeInFormFields|dontSeeInPageSource|dontSeeInSource|dontSeeInTitle|dontSeeLink|dontSeeOptionIsSelected|doubleClick|dragAndDrop|entity|executeJS|executeInSelenium|fillField|formatMoney|generateDate|grabAttributeFrom|grabCookie|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|loadSessionSnapshot|loginAsAdmin|magentoCLI|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|mSetLocale|mResetLocale|openNewTab|pauseExecution|parseFloat|performOn|pressKey|reloadPage|resetCookie|submitForm|resizeWindow|saveSessionSnapshot|scrollTo|scrollToTopOfPage|searchAndMultiSelectOption|see|seeCheckboxIsChecked|seeCookie|seeCurrentUrlEquals|seeCurrentUrlMatches|seeElement|seeElementInDOM|seeInCurrentUrl|seeInField|seeInFormFields|seeInPageSource|seeInPopup|seeInSource|seeInTitle|seeLink|seeNumberOfElements|seeOptionIsSelected|selectOption|setCookie|submitForm|switchToIFrame|switchToNextTab|switchToPreviousTab|switchToWindow|typeInPopup|uncheckOption|unselectOption|wait|waitForAjaxLoad|waitForElement|waitForElementChange|waitForElementNotVisible|waitForElementVisible|waitForJsElementNotVisible|waitForJsElementVisible|waitForJS|waitForLoadingMaskToDisappear|waitForPageLoad|waitForText|assertArrayHasKey|assertArrayNotHasKey|assertArraySubset|assertContains|assertCount|assertEmpty|assertEquals|assertFalse|assertFileExists|assertFileNotExists|assertGreaterOrEquals|assertGreaterThan|assertGreaterThanOrEqual|assertInstanceOf|assertInternalType|assertIsEmpty|assertLessOrEquals|assertLessThan|assertLessThanOrEqual|assertNotContains|assertNotEmpty|assertNotEquals|assertNotInstanceOf|assertNotNull|assertNotRegExp|assertNotSame|assertNull|assertRegExp|assertSame|assertStringStartsNotWith|assertStringStartsWith|assertTrue|expectException|fail|dontSeeFullUrlEquals|dontSee|dontSeeFullUrlMatches|dontSeeInFullUrl|seeFullUrlEquals|seeFullUrlMatches|seeInFullUrl|grabFromFullUrl">
1212
]>
1313

1414
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../src/Magento/FunctionalTestingFramework/ObjectManager/etc/config.xsd">

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,18 +380,45 @@ public function waitForPageLoad($timeout = null)
380380
}
381381

382382
/**
383-
* Wait for all React JavaScript to finish executing.
383+
* Wait for an Element to NOT be visible using JavaScript.
384384
*
385-
* @param integer $timeout
385+
* @param null $selector
386+
* @param null $timeout
386387
* @throws \Exception
387388
* @return void
388389
*/
389-
public function waitForReactPageLoad($timeout = null)
390+
public function waitForJsElementNotVisible($selector, $timeout = null)
390391
{
391392
$timeout = $timeout ?? $this->_getConfig()['pageload_timeout'];
392393

393-
$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);
394-
$this->waitForJS("return document.readyState == 'complete';", $timeout);
394+
// Determine what type of Selector is used.
395+
// Then use the correct JavaScript to locate the Element.
396+
if (\Codeception\Util\Locator::isXPath($selector)) {
397+
$this->waitForJS("return !document.evaluate(`$selector`, document);", $timeout);
398+
} else {
399+
$this->waitForJS("return !document.querySelector(`$selector`);", $timeout);
400+
}
401+
}
402+
403+
/**
404+
* Wait for an Element to be visible using JavaScript.
405+
*
406+
* @param null $selector
407+
* @param null $timeout
408+
* @throws \Exception
409+
* @return void
410+
*/
411+
public function waitForJsElementVisible($selector, $timeout = null)
412+
{
413+
$timeout = $timeout ?? $this->_getConfig()['pageload_timeout'];
414+
415+
// Determine what type of Selector is used.
416+
// Then use the correct JavaScript to locate the Element.
417+
if (\Codeception\Util\Locator::isXPath($selector)) {
418+
$this->waitForJS("return !!document && !!document.evaluate(`$selector`, document);", $timeout);
419+
} else {
420+
$this->waitForJS("return !!document && !!document.querySelector(`$selector`);", $timeout);
421+
}
395422
}
396423

397424
/**

src/Magento/FunctionalTestingFramework/Test/etc/Actions/waitActions.xsd

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
<xs:element type="waitForJSType" name="waitForJS" minOccurs="0" maxOccurs="unbounded"/>
2121
<xs:element type="waitForLoadingMaskToDisappearType" name="waitForLoadingMaskToDisappear" minOccurs="0" maxOccurs="unbounded"/>
2222
<xs:element type="waitForPageLoadType" name="waitForPageLoad" minOccurs="0" maxOccurs="unbounded"/>
23-
<xs:element type="waitForReactPageLoadType" name="waitForReactPageLoad" minOccurs="0" maxOccurs="unbounded"/>
23+
<xs:element type="waitForJsElementNotVisibleType" name="waitForJsElementNotVisible" minOccurs="0" maxOccurs="unbounded"/>
24+
<xs:element type="waitForJsElementVisibleType" name="waitForJsElementVisible" minOccurs="0" maxOccurs="unbounded"/>
2425
<xs:element type="waitForTextType" name="waitForText" minOccurs="0" maxOccurs="unbounded"/>
2526
</xs:choice>
2627
</xs:group>
@@ -166,7 +167,7 @@
166167
<xs:complexType name="waitForPageLoadType">
167168
<xs:annotation>
168169
<xs:documentation>
169-
Waits up to given time for page to have finished loading..
170+
Waits up to given time for page to have finished loading.
170171
</xs:documentation>
171172
</xs:annotation>
172173
<xs:simpleContent>
@@ -177,15 +178,31 @@
177178
</xs:simpleContent>
178179
</xs:complexType>
179180

180-
<xs:complexType name="waitForReactPageLoadType">
181+
<xs:complexType name="waitForJsElementNotVisibleType">
181182
<xs:annotation>
182183
<xs:documentation>
183-
Waits up to given time for React page to have finished loading..
184+
Waits up to given time for a React Element to disappear from the screen using JavaScript.
184185
</xs:documentation>
185186
</xs:annotation>
186187
<xs:simpleContent>
187188
<xs:extension base="xs:string">
188189
<xs:attribute ref="time"/>
190+
<xs:attribute ref="selector"/>
191+
<xs:attributeGroup ref="commonActionAttributes"/>
192+
</xs:extension>
193+
</xs:simpleContent>
194+
</xs:complexType>
195+
196+
<xs:complexType name="waitForJsElementVisibleType">
197+
<xs:annotation>
198+
<xs:documentation>
199+
Waits up to given time for a React Element to appear on the screen using JavaScript.
200+
</xs:documentation>
201+
</xs:annotation>
202+
<xs:simpleContent>
203+
<xs:extension base="xs:string">
204+
<xs:attribute ref="time"/>
205+
<xs:attribute ref="selector"/>
189206
<xs:attributeGroup ref="commonActionAttributes"/>
190207
</xs:extension>
191208
</xs:simpleContent>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,8 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
10451045
case "waitForElement":
10461046
case "waitForElementVisible":
10471047
case "waitForElementNotVisible":
1048+
case "waitForJsElementVisible":
1049+
case "waitForJsElementNotVisible":
10481050
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $time);
10491051
break;
10501052
case "waitForPageLoad":

0 commit comments

Comments
 (0)