Confused on PhantomJS Options and Usage with Node.js and Cucumber.js

60 views
Skip to first unread message

CoffeeAddict

unread,
Mar 31, 2015, 8:22:41 PM3/31/15
to phan...@googlegroups.com
I am new to PhantomJS.

I'm using Cucumber.js and trying to incorporate PhantomJS so that my step_definitions for Cucumber can take advantage of Phantom's page instance to open a certain route during my BDD testing.

I'm sorta grey on a lot of things as a newbie to PhantomJS.  I've read the docs best I can.  

First off, I came across this PhantomJS wrapper: PhantomJS wrapper for Node and it states in the docs there that this wrapper allows you to use PhantomJS with Node.  So is it true you still can't use something like this with Node?:


var page = require('webpage').create();
page.open('http://example.com', function(status) {
  console.log("Status: " + status);
  if(status === "success") {
    page.render('example.png');
  }
  phantom.exit();
});
Because I did try to use that, and it didn't like the require('webpage') because my js code said it was not aware of what "webpage" module was.  That's why I researched and found that Phantom for Node wrapper link above.  So should I be able to still use the vanilla PhantomJS code above here without using that wrapper?

James M. Greene

unread,
Mar 31, 2015, 8:42:43 PM3/31/15
to phan...@googlegroups.com

No, you cannot use a vanilla PhantomJS script in Node.js unless you are doing so via a low-level `child_process` call. When you choose any Node.js wrapper for PhantomJS (of which there are quite a few), you MUST read that wrappers documentation to see how it works.

For example, the "phantom" module you are using:
   https://www.npmjs.com/package/phantom

Most come with lots of caveats, which is not implicitly bad BUT you need to familiarize yourself with them.

Sincerely,
   James M. Greene

--
You received this message because you are subscribed to the Google Groups "phantomjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phantomjs+...@googlegroups.com.
Visit this group at http://groups.google.com/group/phantomjs.
For more options, visit https://groups.google.com/d/optout.

CoffeeAddict

unread,
Apr 2, 2015, 2:35:09 PM4/2/15
to phan...@googlegroups.com
Thanks James.
Reply all
Reply to author
Forward
0 new messages