Skip to content

Commit 727c9c4

Browse files
authored
Merge pull request magento#288 from magento/MQE-1382-WaitForReactPageLoad
MQE-1382: New PWA "waitFor" Actions
2 parents a88548b + cbe914b commit 727c9c4

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
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|waitForPwaElementNotVisible|waitForPwaElementVisible|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">
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\FunctionalTestingFramework\Module;
8+
9+
/**
10+
* Class MagentoPwaActions
11+
*
12+
* Contains all custom PWA action functions to be used in PWA tests.
13+
*
14+
* @package Magento\FunctionalTestingFramework\Module
15+
*/
16+
class MagentoPwaWebDriver extends MagentoWebDriver
17+
{
18+
/**
19+
* Wait for a PWA Element to NOT be visible using JavaScript.
20+
*
21+
* @param null $selector
22+
* @param null $timeout
23+
* @throws \Exception
24+
* @return void
25+
*/
26+
public function waitForPwaElementNotVisible($selector, $timeout = null)
27+
{
28+
$timeout = $timeout ?? $this->_getConfig()['pageload_timeout'];
29+
30+
// Determine what type of Selector is used.
31+
// Then use the correct JavaScript to locate the Element.
32+
if (\Codeception\Util\Locator::isXPath($selector)) {
33+
$this->waitForJS("return !document.evaluate(`$selector`, document);", $timeout);
34+
} else {
35+
$this->waitForJS("return !document.querySelector(`$selector`);", $timeout);
36+
}
37+
}
38+
39+
/**
40+
* Wait for a PWA Element to be visible using JavaScript.
41+
*
42+
* @param null $selector
43+
* @param null $timeout
44+
* @throws \Exception
45+
* @return void
46+
*/
47+
public function waitForPwaElementVisible($selector, $timeout = null)
48+
{
49+
$timeout = $timeout ?? $this->_getConfig()['pageload_timeout'];
50+
51+
// Determine what type of Selector is used.
52+
// Then use the correct JavaScript to locate the Element.
53+
if (\Codeception\Util\Locator::isXPath($selector)) {
54+
$this->waitForJS("return !!document && !!document.evaluate(`$selector`, document);", $timeout);
55+
} else {
56+
$this->waitForJS("return !!document && !!document.querySelector(`$selector`);", $timeout);
57+
}
58+
}
59+
}

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +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="waitForPwaElementNotVisibleType" name="waitForPwaElementNotVisible" minOccurs="0" maxOccurs="unbounded"/>
24+
<xs:element type="waitForPwaElementVisibleType" name="waitForPwaElementVisible" minOccurs="0" maxOccurs="unbounded"/>
2325
<xs:element type="waitForTextType" name="waitForText" minOccurs="0" maxOccurs="unbounded"/>
2426
</xs:choice>
2527
</xs:group>
@@ -165,7 +167,7 @@
165167
<xs:complexType name="waitForPageLoadType">
166168
<xs:annotation>
167169
<xs:documentation>
168-
Waits up to given time for page to have finished loading..
170+
Waits up to given time for page to have finished loading.
169171
</xs:documentation>
170172
</xs:annotation>
171173
<xs:simpleContent>
@@ -176,6 +178,36 @@
176178
</xs:simpleContent>
177179
</xs:complexType>
178180

181+
<xs:complexType name="waitForPwaElementNotVisibleType">
182+
<xs:annotation>
183+
<xs:documentation>
184+
Waits up to given time for a PWA Element to disappear from the screen using JavaScript.
185+
</xs:documentation>
186+
</xs:annotation>
187+
<xs:simpleContent>
188+
<xs:extension base="xs:string">
189+
<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="waitForPwaElementVisibleType">
197+
<xs:annotation>
198+
<xs:documentation>
199+
Waits up to given time for a PWA 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"/>
206+
<xs:attributeGroup ref="commonActionAttributes"/>
207+
</xs:extension>
208+
</xs:simpleContent>
209+
</xs:complexType>
210+
179211
<xs:complexType name="waitForTextType">
180212
<xs:annotation>
181213
<xs:documentation>

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 "waitForPwaElementVisible":
1049+
case "waitForPwaElementNotVisible":
10481050
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $time);
10491051
break;
10501052
case "waitForPageLoad":

0 commit comments

Comments
 (0)