-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathMagentoPwaWebDriver.php
98 lines (90 loc) · 3.17 KB
/
MagentoPwaWebDriver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\Module;
use Codeception\Module\WebDriver;
/**
* Class MagentoPwaActions
*
* Contains all custom PWA action functions to be used in PWA tests.
*
* @package Magento\FunctionalTestingFramework\Module
*/
class MagentoPwaWebDriver extends MagentoWebDriver
{
/**
* List of known PWA loading masks by selector
*
* Overriding the MagentoWebDriver array to contain applicable PWA locators.
*
* @var array
*/
protected $loadingMasksLocators = [
'//div[contains(@class, "indicator-global-")]',
'//div[contains(@class, "indicator-root-")]',
'//img[contains(@class, "indicator-indicator-")]',
'//span[contains(@class, "indicator-message-")]'
];
/**
* Go to the page.
*
* Overriding the MagentoWebDriver version because it contains 'waitForPageLoad'.
* The AJAX check in 'waitForPageLoad' does NOT work with a PWA.
*
* @param string $page
* @param integer $timeout
* @throws \Exception
* @return void
*/
public function amOnPage($page, $timeout = null)
{
WebDriver::amOnPage($page);
$this->waitForLoadingMaskToDisappear($timeout);
}
/**
* Wait for a PWA Element to NOT be visible using JavaScript.
* Add the WAIT_TIMEOUT variable to your .env file for this action.
*
* @param string $selector
* @param integer $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->waitForLoadingMaskToDisappear($timeout);
$this->waitForJS("return !document.evaluate(`$selector`, document);", $timeout);
} else {
$this->waitForLoadingMaskToDisappear($timeout);
$this->waitForJS("return !document.querySelector(`$selector`);", $timeout);
}
}
/**
* Wait for a PWA Element to be visible using JavaScript.
* Add the WAIT_TIMEOUT variable to your .env file for this action.
*
* @param string $selector
* @param integer $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->waitForLoadingMaskToDisappear($timeout);
$this->waitForJS("return !!document && !!document.evaluate(`$selector`, document);", $timeout);
} else {
$this->waitForLoadingMaskToDisappear($timeout);
$this->waitForJS("return !!document && !!document.querySelector(`$selector`);", $timeout);
}
}
}