diff --git a/src/Codeception/Coverage/Subscriber/LocalServer.php b/src/Codeception/Coverage/Subscriber/LocalServer.php index 86e9bc33e3..d15b9cba3b 100644 --- a/src/Codeception/Coverage/Subscriber/LocalServer.php +++ b/src/Codeception/Coverage/Subscriber/LocalServer.php @@ -9,6 +9,7 @@ use Codeception\Events; use Codeception\Exception\ModuleException; use Codeception\Exception\RemoteException; +use Facebook\WebDriver\Exception\NoSuchAlertException; /** * When collecting code coverage data from local server HTTP requests are sent to c3.php file. @@ -242,6 +243,19 @@ protected function startCoverageCollection($testName) protected function fetchErrors() { + // Calling grabCookie() while an alert is present dismisses the alert + // @see https://github.com/Codeception/Codeception/issues/1485 + if ($this->module instanceof \Codeception\Module\WebDriver) { + try { + $alert = $this->module->webDriver->switchTo()->alert(); + $alert->getText(); + // If this succeeds an alert is present, abort + return; + } catch (NoSuchAlertException $e) { + // No alert present, continue + } + } + try { $error = $this->module->grabCookie(self::COVERAGE_COOKIE_ERROR); } catch (ModuleException $e) {