Skip to content

Commit

Permalink
Merge pull request #742 from magento-obsessive-owls/PWA-691
Browse files Browse the repository at this point in the history
PWA-691: Fix Waits In PWA MFTF MagentoPwaWebDriver
  • Loading branch information
okolesnyk authored Jun 17, 2020
2 parents 360beb4 + 821a4d5 commit edb5c49
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit edb5c49

Please sign in to comment.