Codeception: Unable to interact with window popups using PhantomJS

Created on 3 Sep 2014  路  7Comments  路  Source: Codeception/Codeception

I'm not 100% sure if this is a Codeception issue but I figured this would be a good place to start

Issue

I came across an issue where I'm unable to interact with a window.confirm when using PhantomJS with the WebDriver module.

Using the exact same test with a manually started Selenium server and Firefox works as expected.

Example

I've set up a repository for Codeception tests and have a branch, failingPopup that has everything set up to reproduce the issue. It also mirrors the setup I'm using in my project.

The Popup acceptance test manually creates a window.confirm popup and tries to confirm text within and then accepts the popup.

This test works as expected with Firefox+Selenium but fails when using PhantomJS


Any help on this is greatly appreciated. Since you know what exactly Codeception is doing behind the scenes you may think that this issue is better suited for one of the other parts involved, like PhantomJS or WebDriver. Please let me know if this is should be posted elsewhere. I just wanted to check if it might be a Codeception issue first.

Most helpful comment

This is how I wrote it for this scenario:
When the delete button is clicked, it will display a Javascript confirm popup and User needs to click on OK to proceed with the deletion.

...
$I->executeJS("window.confirm = function(msg){return true;};");
$I->click('.btn-delete', 'table.items tbody td.button-column');
...

All 7 comments

Known issue, internal popup tests failing when running with phantomjs. Not a bug of Codeception, anyway.

Here what StackOverflow say about PhantomJS in Ghostdriver mode:

Problem: The GhostDriver API does not yet support alert handling. There is an acceptable workaround for the time being, which is to inject your own javascript into the page that will handle the alert and store it's text for you.

http://stackoverflow.com/questions/15708518/how-can-i-handle-an-alert-with-ghostdriver-via-python

I think proposed solution could be taken into Codeception with executeJs action

Can You help me to write "executeJs" action for accept popup using phantomJS?

This is how I wrote it for this scenario:
When the delete button is clicked, it will display a Javascript confirm popup and User needs to click on OK to proceed with the deletion.

...
$I->executeJS("window.confirm = function(msg){return true;};");
$I->click('.btn-delete', 'table.items tbody td.button-column');
...

Thank you! It works!

@animaster @janeberets
I had the same issue but the scenario you wrote still can't fix. What is the version of phantomjs and codeception you are using?
Im using phantomjs 1.9.7 and codeception 2.1.7
Thank you.

phantomjs 2.1.1 and codeception 2.1.4

@janeberets thank you, it works also in 1.9.7 and codeception 2.1.7
phantomjs 2.1.1 always returns blank screen for me

$js_confirm = 'window.confirm = function(){ return true; }';
$I->executeJS($js_confirm);
$test_page->clickDeleteButton();
$I->executeJS("return window.confirm");

http://stackoverflow.com/questions/19903146/confirm-alert-window-in-phantom-js

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sebastianneubert picture sebastianneubert  路  3Comments

rogoit picture rogoit  路  3Comments

DavertMik picture DavertMik  路  4Comments

marcelodeandrade picture marcelodeandrade  路  3Comments

joshhornby picture joshhornby  路  3Comments