SpookyJS / SpookyJS

Drive CasperJS from Node.js
MIT License
907 stars 107 forks source link

Getting error using 'withPopup' #89

Open marcusellis05 opened 10 years ago

marcusellis05 commented 10 years ago

So, I'm trying to use SppokyJS to capture a screenshot of a popup window. When a user clicks a link, a popup window opens and displays a dynamically generated PDF. The relevant code looks something like:

spooky.then(function(){
  this.click('#mySelector');
});
spooky.waitForPopup(/DisplayPDF/);
spooky.withPopup(/DisplayPDF/, function(){
  this.capture('popup_' + Date.now() + '.png');
});

But I end up getting this error from Casper:

CasperError: Invalid popupInfo type: object.
[ { file: '/usr/local/Cellar/casperjs/1.1-beta3/libexec/modules/pagestack.js',
    line: 104,
    function: 'find' },
  { file: '/usr/local/Cellar/casperjs/1.1-beta3/libexec/modules/casper.js',
    line: 2353,
    function: '_step' },
  { file: '/usr/local/Cellar/casperjs/1.1-beta3/libexec/modules/casper.js',
    line: 1553,
    function: 'runStep' },
  { file: '/usr/local/Cellar/casperjs/1.1-beta3/libexec/modules/casper.js',
    line: 399,
    function: 'checkStep' } ]

It seems that an empty object literal {} is getting passed to Casper's "Popup" methods but I can't figure out why. Any ideas?

marcusellis05 commented 10 years ago

SpookyJS version: 0.2.4 CasperJS version: 1.1.0-beta3 PhantomJS version: 1.9.2

lawnsea commented 10 years ago

I suspect the problem is the regular expression. I don't think those can be serialized to JSON. This is definitely a limitation that needs to be mitigated or documented.

Can you pass a string pattern?

marcusellis05 commented 10 years ago

Tried that but I get:

CasperError: Couldn't find popup with url containing 'PDFServlet'
marcusellis05 commented 10 years ago

So, yeah, I guess the takeaway is addressing the regex issue or documenting the limitation there.

I'll try to figure out why my popup can't be found.

Thanks. And nice work on this, btw. Very helpful.