When comparing PhantomJS vs NW.js (w/xvfb), the Slant community recommends PhantomJS for most people. In the question“What are the best headless browsers for testing?” PhantomJS is ranked 1st while NW.js (w/xvfb) is ranked 3rd.
Ranked in these QuestionsQuestion Ranking
Pro Supports screen capture
Pro Used in many open source projects
Pro Supports many browser standards
PhantomJS has full DOM and CSS parsing, JSON, canvas, and SVG support.
Pro Built on WebKit
WebKit is becoming the gold standard for browser compatibility, making it a good starting point for native headless browser testing.
Pro Active development
Development activity and number of contributors is healthy.
Pro Node integration
The integration of Node with the DOM in NW.js opens up a number of new options in how your headless testing workflow can be facilitated.
Pro NaCl support/integration
Access to the Native Client offers up more options in implementing your testing workflow.
Con Browser closes unexpectedly
It often happens when running on more then 5 (my measurement) JVM instances that the browser gets stuck and quits unexpectedly. This can be partially solved by running the instances one by one instead of parallel (this is a problem when testing Jenkins and Bamboo agents) but I don't believe this qualifies as a solution. The error is called
Con Elements are sometimes not visible
This is an error which occurs with almost no reason, PhantomJS sometimes decides that it cannot click the element even though the element is intractable or enabled.
The error it raises is:
Con Heavy setup
You'll often end up having PhantomJS binaries connected via WebDriver to your testing framework, possibly using client/server especially if you want your test running with something else than Java. This mean an overhead in terms or maintenance and performance, but still usually lighter than running a full browser (like Chrome, Firefox, IE).