Skip to content

Commit

Permalink
Handle modal dialogue which will block all tests in the cms
Browse files Browse the repository at this point in the history
updated as an afterScenario event
  • Loading branch information
Jeffrey Guo committed Sep 22, 2014
1 parent 6e13a68 commit 54eaa63
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/SilverStripe/BehatExtension/Context/BasicContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,34 @@ public function handleAjaxTimeout()
*
* @AfterStep
*/
public function takeScreenshotAfterFailedStep(StepEvent $event)
{
if (4 === $event->getResult()) {
$this->takeScreenshot($event);
}
}
public function takeScreenshotAfterFailedStep(StepEvent $event)
{
if (4 === $event->getResult()) {
$this->takeScreenshot($event);
}
}

/**
* Close modal dialog if test scenario fails on CMS page
*
* @AfterScenario
*/
public function closeModalDialog(ScenarioEvent $event) {
// Only for failed tests on CMS page
if (4 === $event->getResult()) {
$cmsElement = $this->getSession()->getPage()->find('css', '.cms');
if($cmsElement) {
try {
// Navigate away triggered by reloading the page
$this->getSession()->reload();
$this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
} catch(\WebDriver\Exception $e) {
// no-op, alert might not be present
}
}
}
}

/**
* Delete any created files and folders from assets directory
*
Expand Down

0 comments on commit 54eaa63

Please sign in to comment.