Codeception: acceptPopup doesn't work when using CodeCoverage
My acceptance tests works perfectly when I don’t use --coverage (or --coverage-html), but when I do the following error appears (and I have a “$I->acceptPopup();” in this point of the code).
Command:
php codecept.phar run acceptance myTestCept.php --coverage-html -d
[UnexpectedAlertOpenException]
unexpected alert open
(Session info: chrome=38.0.2125.104)
(Driver info: chromedriver=2.10.267521,platform=Windows NT 6.1 SP1 x86_64
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1 milliseconds: null
Build info: version: '2.43.0', revision: '597b76b', time: '2014-09-09 20:52
:14'
System info: host: 'Rafael-PC', ip: '10.1.1.14', os.name: 'Windows 7', os.a
rch: 'x86', os.version: '6.1', java.version: '1.7.0_71'
Session ID: c609d18ac1e286650052fa88369ed083
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, br
owserName=chrome, chrome={userDataDir=C:\Users\Cliente\AppData\Local\Temp\s
coped_dir6936_23574}, rotatable=false, locationContextEnabled=true, version
=38.0.2125.104, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseE
nabled=false, handlesAlerts=true, browserConnectionEnabled=false, nativeEve
nts=true, webStorageEnabled=true, applicationCacheEnabled=false, takesScree
nshot=true}]
Exception trace:
() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/facebook/webdriver/lib/WebDriverExceptions.php:94
WebDriverException::throwException() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/facebook/webdriver/lib/remote/HttpCommandExecutor.php:253
HttpCommandExecutor::curl() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/facebook/webdriver/lib/remote/HttpCommandExecutor.php:153
HttpCommandExecutor::remoteExecute() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/facebook/webdriver/lib/remote/HttpCommandExecutor.php:117
HttpCommandExecutor->execute() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/facebook/webdriver/lib/remote/RemoteWebDriver.php:261
RemoteWebDriver->takeScreenshot() at phar://E:/Auto_testing/Codecept/codecept.phar/src/Codeception/Module/WebDriver.php:197
Codeception\Module\WebDriver->_saveScreenshot() at phar://E:/Auto_testing/Codecept/codecept.phar/src/Codeception/Module/WebDriver.php:137
Codeception\Module\WebDriver->_failed() at phar://E:/Auto_testing/Codecept/codecept.phar/src/Codeception/Subscriber/Module.php:72
Codeception\Subscriber\Module->failed() at n/a:n/a
call_user_func() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php:164
Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php:53
Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at phar://E:/Auto_testing/Codecept/codecept.phar/src/Codeception/PHPUnit/Listener.php:101
Codeception\PHPUnit\Listener->fire() at phar://E:/Auto_testing/Codecept/codecept.phar/src/Codeception/PHPUnit/Listener.php:51
Codeception\PHPUnit\Listener->addError() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/phpunit/phpunit/src/Framework/TestResult.php:269
PHPUnit_Framework_TestResult->addError() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/phpunit/phpunit/src/Framework/TestResult.php:735
PHPUnit_Framework_TestResult->run() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/phpunit/phpunit/src/Framework/TestCase.php:771
PHPUnit_Framework_TestCase->run() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/phpunit/phpunit/src/Framework/TestSuite.php:703
PHPUnit_Framework_TestSuite->run() at phar://E:/Auto_testing/Codecept/codecept.phar/src/Codeception/PHPUnit/Runner.php:100
Codeception\PHPUnit\Runner->doEnhancedRun() at phar://E:/Auto_testing/Codecept/codecept.phar/src/Codeception/SuiteManager.php:153
Codeception\SuiteManager->run() at phar://E:/Auto_testing/Codecept/codecept.phar/src/Codeception/Codecept.php:162
Codeception\Codecept->runSuite() at phar://E:/Auto_testing/Codecept/codecept.phar/src/Codeception/Codecept.php:145
Codeception\Codecept->run() at phar://E:/Auto_testing/Codecept/codecept.phar/src/Codeception/Command/Run.php:177
Codeception\Command\Run->execute() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:252
Symfony\Component\Console\Command\Command->run() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:889
Symfony\Component\Console\Application->doRunCommand() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:193
Symfony\Component\Console\Application->doRun() at phar://E:/Auto_testing/Codecept/codecept.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:124
Symfony\Component\Console\Application->run() at phar://E:/Auto_testing/Codecept/codecept.phar/codecept:34
require_once() at E:\Auto_testing\Codecept\codecept.phar:7
run [-c|--config="..."] [--report] [--html[="..."]] [--xml[="..."]] [--tap[="..."]] [--json[="..."]] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug]
[--coverage[="..."]] [--coverage-html[="..."]] [--coverage-xml[="..."]] [--coverage-text[="..."]] [--no-exit] [-g|--group="..."] [-s|--skip="..."] [-sg|--skip-group="..."] [--env="..."] [-f|--fail-fast] [suite] [test]
My codeception.yml:
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
memory_limit: 1024M
colors: true
steps: true
coverage:
enabled: true
remote: true
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
And my acceptance.suite.yml:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- AcceptanceHelper
config:
WebDriver:
url: 'http://myurl.com/'
browser: 'chrome'
restart: false
window_size: 1024x768
I’m using: Windows 7 Home Premium x64 bits Codeception 2.0.5 php 5.5.12 XDebug 2.2.5
I tried to use
capabilities:
unexpectedAlertBehaviour: 'accept'
in acceptance.suite.yml, but nothing changes…
Am I doing anything wrong?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 19 (7 by maintainers)
Commits related to this issue
- Add workaround for #1485 - don't attempt to read cookies while an alert is open — committed to marcovtwout/Codeception by marcovtwout 3 years ago
- Coverage: Don't attempt to read cookies while an alert is open (#6211) * Add workaround for #1485 - don't attempt to read cookies while an alert is open * Only apply workaround when module is WebD... — committed to Codeception/Codeception by marcovtwout 3 years ago
Nothing new on this?
I hit exactly this bug but would say it is with the Coverage module.
Coverage/Subscriber/LocalServer.php
:194 tries to read a cookie after each test step. Chromedriver fails this with the unexpected alert open.See the following selenium logs for details. There is:
In case coverage is disabled, the cookie read is missing and the test continues normally.
My PoC solution is to disable the error cookie read. In reality, I see two options: a) why is reading cookies even forbidden in this situation? -> Make chromedriver allow this. b) why do we need to read errors after each step? This does not happen without coverage… -> Do this only once in the beginning or after each suite.
I think codecoverage is a good step towards a solid codebase and see this as a major bug stopping people from using it, so I feel this issue should be addressed
@eXorus This issue is still valid and should be reopened.
The analysis done here is exactly correct: https://github.com/Codeception/Codeception/issues/1485#issuecomment-343901313 Attempting
grabCookie()
while an alert is present immediately dismisses the prompt and causes an exception on both latest Chrome and Firefox drivers:Chrome:
Firefox:
As a workaround you can disable the call to
$this->fetchErrors()
inCodeception/Coverage/Subscriber/LocalServer.php
(https://github.com/Codeception/Codeception/blob/4.1/src/Codeception/Coverage/Subscriber/LocalServer.php#L97). Note that this obviously will cause c3 collection errors to remain silent.A better solution is option B proposed in https://github.com/Codeception/Codeception/issues/1485#issuecomment-343901313
This workaround works for me, if you want to press on “Submit” or “OK” button.
I think I found the reason. After popup is displayed, acceptPopup() should be called, but grabCookie() is called, thats why WebDriver fail with UnexpectedAlertOpenException. Now it work something like: $I->click(‘something’); Codeception\Coverage\Subscriber\LocalServer::afterStep() ->Codeception\Coverage\Subscriber\LocalServer::fetchErrors() ->webdriver->grabCookie(self::COVERAGE_COOKIE_ERROR); $I->acceptPopup();//never called, since it failed on grabCookie() before
But what is solution? skip grabCookie() if popup is displayed?
Same issue. Any workaround ?