17
17
*/
18
18
class MagentoPwaWebDriver extends MagentoWebDriver
19
19
{
20
+ /**
21
+ * List of known PWA loading masks by selector
22
+ *
23
+ * Overriding the MagentoWebDriver array to contain applicable PWA locators.
24
+ *
25
+ * @var array
26
+ */
27
+ protected $ loadingMasksLocators = [
28
+ '//div[contains(@class, "indicator-global-")] ' ,
29
+ '//div[contains(@class, "indicator-root-")] ' ,
30
+ '//img[contains(@class, "indicator-indicator-")] ' ,
31
+ '//span[contains(@class, "indicator-message-")] '
32
+ ];
33
+
20
34
/**
21
35
* Go to the page.
22
36
*
23
37
* Overriding the MagentoWebDriver version because it contains 'waitForPageLoad'.
24
38
* The AJAX check in 'waitForPageLoad' does NOT work with a PWA.
25
39
*
26
- * @param string $page
40
+ * @param string $page
41
+ * @param integer $timeout
27
42
* @throws \Exception
28
43
* @return void
29
44
*/
30
- public function amOnPage ($ page )
45
+ public function amOnPage ($ page, $ timeout = null )
31
46
{
32
47
WebDriver::amOnPage ($ page );
48
+ $ this ->waitForLoadingMaskToDisappear ($ timeout );
33
49
}
34
50
35
51
/**
36
52
* Wait for a PWA Element to NOT be visible using JavaScript.
37
53
* Add the WAIT_TIMEOUT variable to your .env file for this action.
38
54
*
39
- * @param null $selector
40
- * @param null $timeout
55
+ * @param string $selector
56
+ * @param integer $timeout
41
57
* @throws \Exception
42
58
* @return void
43
59
*/
44
60
public function waitForPwaElementNotVisible ($ selector , $ timeout = null )
45
61
{
62
+ $ timeout = $ timeout ?? $ this ->_getConfig ()['pageload_timeout ' ];
63
+
46
64
// Determine what type of Selector is used.
47
65
// Then use the correct JavaScript to locate the Element.
48
66
if (\Codeception \Util \Locator::isXPath ($ selector )) {
67
+ $ this ->waitForLoadingMaskToDisappear ($ timeout );
49
68
$ this ->waitForJS ("return !document.evaluate(` $ selector`, document); " , $ timeout );
50
69
} else {
70
+ $ this ->waitForLoadingMaskToDisappear ($ timeout );
51
71
$ this ->waitForJS ("return !document.querySelector(` $ selector`); " , $ timeout );
52
72
}
53
73
}
@@ -56,18 +76,22 @@ public function waitForPwaElementNotVisible($selector, $timeout = null)
56
76
* Wait for a PWA Element to be visible using JavaScript.
57
77
* Add the WAIT_TIMEOUT variable to your .env file for this action.
58
78
*
59
- * @param null $selector
60
- * @param null $timeout
79
+ * @param string $selector
80
+ * @param integer $timeout
61
81
* @throws \Exception
62
82
* @return void
63
83
*/
64
84
public function waitForPwaElementVisible ($ selector , $ timeout = null )
65
85
{
86
+ $ timeout = $ timeout ?? $ this ->_getConfig ()['pageload_timeout ' ];
87
+
66
88
// Determine what type of Selector is used.
67
89
// Then use the correct JavaScript to locate the Element.
68
90
if (\Codeception \Util \Locator::isXPath ($ selector )) {
91
+ $ this ->waitForLoadingMaskToDisappear ($ timeout );
69
92
$ this ->waitForJS ("return !!document && !!document.evaluate(` $ selector`, document); " , $ timeout );
70
93
} else {
94
+ $ this ->waitForLoadingMaskToDisappear ($ timeout );
71
95
$ this ->waitForJS ("return !!document && !!document.querySelector(` $ selector`); " , $ timeout );
72
96
}
73
97
}
0 commit comments