Skip to content
This repository

.click() does not work well with popup links #139

Closed
starlocke opened this Issue June 05, 2012 · 9 comments

4 participants

Victor Yap Nicolas Perriault Eric BREHAULT Tom Robinson
Victor Yap

Filed with PhantomJS...
http://code.google.com/p/phantomjs/issues/detail?id=151

I'm using CasperJS to do my automated testing, and doing the combination (code below) fails in an unexpected way. I was expecting that the last assert to be successful, but it fails since the focused window does not navigate away, and the popup windows is in limbo (it seems unsupported now in PhantomJS).

Clicking through <a target="_blank"> and similar popup-type links should at least throw some kind of Warning, or Exception... at least while we wait for full support as described in comment 3 (open, focus, close, resize, etc) [of the filing with PhantomJS].

casper.then(function() {
  this.test.assertExists(x("//a[text()='Preview']"), 'Preview Btn Exists');
  this.click(x("//a[text()='Preview']")); // Does not open a popup (or does not automatically focus on it).
});
casper.then(function() {
  this.test.assertExist("div.the_preview", 'Looking at preview');
  this.capture('/tmp/foo.png'); // will be looking that the page with the button, unexpectedly, with no warnings.
});
Eric BREHAULT

It looks pretty similar to issue #138
(In my case, using a CSS selector instead of a XPath selector looks like a good workaround).

Victor Yap

Hm. That's a good point. I noticed that issue before writing this report, but I was convinced that it was target="_blank" causing the problems, because, I simply removed target="_blank" and everything worked out as expected.

Let's test the same thing, then, but instead of removing target="_blank", add an id="the_link" !

Nicolas Perriault
Owner
n1k0 commented June 05, 2012

Nothing related to issue #138. Sample test script:

var casper = require('casper').create();

casper.start();

casper.then(function() {
    this.page.content = '<a href="http://google.fr/">Google</a>';
    this.clickLabel('Google');
});

casper.then(function() {
    this.test.assertTitle('Google', "I've loaded Google");
    this.page.content = '<a href="http://google.fr/" target="_blank">Google</a>';
    this.clickLabel('Google');
});

casper.then(function() {
    this.test.assertTitle('Google', "I've loaded Google");
});

casper.run(function() {
    this.test.renderResults(true);
});

Run:

$ casperjs t.js
PASS I've loaded Google
FAIL I've loaded Google
#    type: assertTitle
#    details: Page title is not the one expected
#    subject: ""
#    expected: "Google"
FAIL 2 tests executed, 1 passed, 1 failed.                                      

Details for the 1 failed test:

In null:0
   assertTitle: I've loaded Google

This will be solved only when phantomjs will fix http://code.google.com/p/phantomjs/issues/detail?id=151 indeed.

Victor Yap

@n1k0 Nice analysis and test-case! Good job.

Tom Robinson

http://code.google.com/p/phantomjs/issues/detail?id=151 is fixed, popup windows are supported in phantomjs 1.7.

Now how about Casper? Is there a way to wait for a popup to be opened, then do some stuff on that page, and switch back?

Nicolas Perriault
Owner

@tlrobinson indeed, that would be plain handy. Though I don't have an API in mind, do you have any suggestion? eg:

casper.waitForPopup('<id?>', function(popup) {
    this.echo(popup.url + ' is loaded and is the current active page');
    popup.close();
});

But I'm not convinced at all :/

Tom Robinson
Nicolas Perriault
Owner

Casper doesn't really support using two pages in a single flow, does it?

Not really atm, but that may be worked out, with a bit of refactoring though. The coupling between a casper instance and a page is nasty and was a bad design decision at the time the project was started, but I have hopes it can evolve to something more decoupled in the future — though we may wait for a 2.0 for that.

In the meanwhile, my current approach is to try to provide features without redoing everything from scratch nor breaking BC for existing users. I know it's a bit frustrating, but casperjs is just a pet project for me right now and I don't see much PRs nor design proposal coming, that's why I'm often asking for a bit of help :)

Nicolas Perriault
Owner

Fixed with the addition of waitForPopup() & withPopup()

Nicolas Perriault n1k0 closed this December 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.