Base scenario is:
$I->amOnPage(...);
$I->click($deleteButton);
$I->seeInPopup('Are you sure?');
$I->acceptPopup(); //'OK'
$I->waitForElement($usersTable);
$I->seeInCurrentUrl($someUrl);
I am on page "/#/user/22/update/"
[GET] .../#/user/22/update/
I click "#user_delete"
[Selenium server Logs]
19:09:04.425 INFO - Capabilities are: {
"browserName": "chrome",
"unexpectedAlertBehaviour": "ignore",
"unhandledPromptBehavior": "ignore",
}
19:09:04.425 INFO - Matched factory org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
19:09:05.894 INFO - Detected dialect: OSS
19:09:05.949 INFO - Started new session b73a58b094216e24e24194373583c930 (org.openqa.selenium.chrome.ChromeDriverService)
....
[Selenium driver Logs]
19:09:31.179 WARNING - Unable to evaluate script: unexpected alert open
19:09:31.189 WARNING - Unable to evaluate script: unexpected alert open
Unable to retrieve screenshot from Selenium : unexpected alert open: {Alert text : Are you sure?}
(Session info: chrome=67.0.3396.99)
(Driver info: chromedriver=2.37 (0),platform=Linux 4.4.0-130-generic x86_64)
Unable to retrieve source page from Selenium : unexpected alert open: {Alert text : Are you sure?}
(Session info: chrome=67.0.3396.99)
(Driver info: chromedriver=2.37 (0),platform=Linux 4.4.0-130-generic x86_64)
Screenshot and page source were saved into '/.../tests/_output/' dir
ERROR
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
โบ Records saved into: file:///.../tests/_output/records.html
-----
[Facebook\WebDriver\Exception\UnexpectedAlertOpenException] unexpected alert open: {Alert text : Are you sure?}
(Session info: chrome=67.0.3396.99)
(Driver info: chromedriver=2.37 (0),platform=Linux 4.4.0-130-generic x86_64)
Scenario Steps:
12. $I->click("#user_delete") at tests/acceptance/UserEditCest.php:261
11. $I->amOnPage("/#/user/22/update/") at tests/acceptance/UserEditCest.php:253
...
#1 .../vendor/facebook/webdriver/lib/Exception/WebDriverException.php:140
#2 .../vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
#3 .../vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:547
#4 .../vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:332
#5 .../vendor/symfony/event-dispatcher/EventDispatcher.php:212
#6 .../vendor/symfony/event-dispatcher/EventDispatcher.php:44
#7 .../tests/_support/_generated/AcceptanceTesterActions.php:1556
#8 .../tests/acceptance/UserEditCest.php:261
#9 tests\acceptance\UserEditCest->deleteUser
Now pass with
//...
try {
$I->click($deleteButton);
} catch (\Facebook\WebDriver\Exception\WebDriverException $e) {
codecept_debug($e->getMessage());
}
$I->seeInPopup('Are you sure?');
$I->acceptPopup(); //'OK'
//...
How to interact with alerts correctly?
actor: AcceptanceTester
modules:
enabled:
- \Helper\Acceptance
- Asserts
- \Module\WebDriver
config:
\Module\WebDriver:
url: ...
browser: chrome
port: 4444
window_size: '1920x1080'
wait: 5
restart: true
clear_cookies: true
capabilities:
unexpectedAlertBehaviour: 'ignore'
Your click step fails for some reason, please tell us what exception message you get logged there.
Sorry for long delay with answer.
For now I see UnexpectedAlertOpenException when I use Codeception\Module\AngularJS as ancestor of my \Helper\WebDriver module.
Code is:
//SomeCest
public function deleteVno(AdminTester $I)
{
$popupMsg = 'Are you sure?';
$href = $this->vnoHref;
$I->amOnPage($href);
$I->click('Delete');
$I->seeInPopup($popupMsg);
$I->acceptPopup();
$I->seeFlashText('Vno deleted.');
$I->seeCurrentUrlEquals('.../');
$I->dontSeeLink($href);
}
Original error msg is:
1) ...Cest: Delete vno
Test acceptance/...Cest.php:deleteVno
[Facebook\WebDriver\Exception\UnexpectedAlertOpenException] unexpected alert open: {Alert text : Are you sure?}
(Session info: chrome=67.0.3396.99)
(Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 4.4.0-137-generic x86_64)
Scenario Steps:
#1 /home/alex/dev1_opt/www/eastar/nms_tests/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:140
#2 /home/alex/dev1_opt/www/eastar/nms_tests/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
#3 /home/alex/dev1_opt/www/eastar/nms_tests/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:547
#4 /home/alex/dev1_opt/www/eastar/nms_tests/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:332
#5 /home/alex/dev1_opt/www/eastar/nms_tests/vendor/symfony/event-dispatcher/EventDispatcher.php:212
#6 /home/alex/dev1_opt/www/eastar/nms_tests/vendor/symfony/event-dispatcher/EventDispatcher.php:44
#7 /home/alex/dev1_opt/www/eastar/nms_tests/_support/_generated/AcceptanceTesterActions.php:339
#8 /home/alex/dev1_opt/www/eastar/nms_tests/acceptance/...Cest.php:205
#9 acceptance\NetworkCest->deleteVno
#10 /home/alex/dev1_opt/www/eastar/nms_tests/codecept:12
ERRORS!
Tests: 1, Assertions: 1, Errors: 1.
My hotfix is:
// \Helper\WebDriver extends \Codeception\Module\AngularJS
public function _afterStep(Step $step){
try{
parent::_afterStep($step);
}catch(\Facebook\WebDriver\Exception\UnexpectedAlertOpenException $e){
//ignore
}
}
Not sure how to fix it better (?).
I don't think that this issue was a bug of Codeception
Most helpful comment
Sorry for long delay with answer.
For now I see UnexpectedAlertOpenException when I use
Codeception\Module\AngularJSas ancestor of my \Helper\WebDriver module.Code is:
Original error msg is:
My hotfix is:
Not sure how to fix it better (?).