Skip to content

Commit e2323a2

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

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,21 @@ public function waitForPageLoad($timeout = null)
379379
$this->waitForLoadingMaskToDisappear($timeout);
380380
}
381381

382+
/**
383+
* Wait for all React JavaScript to finish executing.
384+
*
385+
* @param integer $timeout
386+
* @throws \Exception
387+
* @return void
388+
*/
389+
public function waitForReactPageLoad($timeout = null)
390+
{
391+
$timeout = $timeout ?? $this->_getConfig()['pageload_timeout'];
392+
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);
395+
}
396+
382397
/**
383398
* Wait for all visible loading masks to disappear. Gets all elements by mask selector, then loops over them.
384399
*

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
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"/>
2324
<xs:element type="waitForTextType" name="waitForText" minOccurs="0" maxOccurs="unbounded"/>
2425
</xs:choice>
2526
</xs:group>
@@ -176,6 +177,20 @@
176177
</xs:simpleContent>
177178
</xs:complexType>
178179

180+
<xs:complexType name="waitForReactPageLoadType">
181+
<xs:annotation>
182+
<xs:documentation>
183+
Waits up to given time for React page to have finished loading..
184+
</xs:documentation>
185+
</xs:annotation>
186+
<xs:simpleContent>
187+
<xs:extension base="xs:string">
188+
<xs:attribute ref="time"/>
189+
<xs:attributeGroup ref="commonActionAttributes"/>
190+
</xs:extension>
191+
</xs:simpleContent>
192+
</xs:complexType>
193+
179194
<xs:complexType name="waitForTextType">
180195
<xs:annotation>
181196
<xs:documentation>

0 commit comments

Comments
 (0)