Merge pull request #3900 from chillu/pulls/behat-wait-cms-load

Behat: Wait until CMS loading overlay is removed
This commit is contained in:
Daniel Hensby 2016-04-06 15:19:55 +01:00
commit c7de1f40e1

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$/
*/