Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWA-691: Fix Waits In PWA MFTF MagentoPwaWebDriver #742

Merged
merged 6 commits into from Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,37 +17,57 @@
*/
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 string $page
* @param integer $timeout
* @throws \Exception
* @return void
*/
public function amOnPage($page)
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 null $selector
* @param null $timeout
* @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);
}
}
Expand All @@ -56,18 +76,22 @@ public function waitForPwaElementNotVisible($selector, $timeout = null)
* Wait for a PWA Element to be visible using JavaScript.
* Add the WAIT_TIMEOUT variable to your .env file for this action.
*
* @param null $selector
* @param null $timeout
* @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);
}
}
Expand Down
Expand Up @@ -63,7 +63,7 @@ class MagentoWebDriver extends WebDriver
*
* @var array
*/
public static $loadingMasksLocators = [
protected $loadingMasksLocators = [
'//div[contains(@class, "loading-mask")]',
'//div[contains(@class, "admin_data-grid-loading-mask")]',
'//div[contains(@class, "admin__data-grid-loading-mask")]',
Expand Down Expand Up @@ -439,7 +439,9 @@ public function waitForPageLoad($timeout = null)
*/
public function waitForLoadingMaskToDisappear($timeout = null)
{
foreach (self::$loadingMasksLocators as $maskLocator) {
$timeout = $timeout ?? $this->_getConfig()['pageload_timeout'];

foreach ($this->loadingMasksLocators as $maskLocator) {
// Get count of elements found for looping.
// Elements are NOT useful for interaction, as they cannot be fed to codeception actions.
$loadingMaskElements = $this->_findElements($maskLocator);
Expand Down