Behat: Wait until CMS loading overlay is removed

This makes tests more robust at the expense of an additional
check with every step. The "ajax steps" logic works similarly,
but does not respect the loading indicator. While this logic
waits for a short time after ajax requests are finished,
in some cases that isn't enough time for the browser to
process the response and remove the loading indicator.
Since the "ajax steps" logic applies to operations outside of the CMS
as well, we can't add the loading indicator check there.
This commit is contained in:
Ingo Schommer 2015-02-15 10:46:24 +13:00
parent 7ba4b5b6ef
commit fb660225c2

View File

@ -6,6 +6,7 @@ use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Context\Step,
Behat\Behat\Event\StepEvent,
Behat\Behat\Exception\PendingException,
Behat\Mink\Exception\ElementNotFoundException,
Behat\Gherkin\Node\PyStringNode,
@ -43,6 +44,25 @@ class CmsUiContext extends BehatContext {
return $this->getMainContext()->getSession($name);
}
/**
* Wait until CMS loading overlay isn't present.
* This is an addition to the "ajax steps" logic in
* SilverStripe\BehatExtension\Context\BasicContext
* which also waits for any ajax requests to finish before continuing.
*
* The check also applies in when not in the CMS, which is a structural issue:
* Every step could cause the CMS to be loaded, and we don't know if we're in the
* CMS UI until we run a check.
*
* @AfterStep
*/
public function handleCmsLoadingAfterStep(StepEvent $event) {
$timeoutMs = $this->getMainContext()->getAjaxTimeout();
$this->getSession()->wait($timeoutMs,
"document.getElementsByClassName('cms-content-loading-overlay').length == 0"
);
}
/**
* @Then /^I should see the CMS$/
*/