Skip to content

Commit

Permalink
Coverage: Don't attempt to read cookies while an alert is open (#6211)
Browse files Browse the repository at this point in the history
* Add workaround for #1485 - don't attempt to read cookies while an alert is open

* Only apply workaround when module is WebDriver
  • Loading branch information
marcovtwout committed May 28, 2021
1 parent 1d9e1a2 commit 91d6cb0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Codeception/Coverage/Subscriber/LocalServer.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 91d6cb0

Please sign in to comment.