I'm not sure why PhantomJS is necessary and I'm hoping someone can help.
JavaScript that requires a DOM needs someplace to run, normally in the browser. So test frameworks often fire up a browser which they then control in order to run the tests & carry out asserts. The test frameworks themselves often can't control the browser directly, so you end up with three layers to your test:
Simply, PhantomJS is a browser which runs headlessly (i.e. doesn't draw out the the screen). The benefits that brings is speed — if you're controlling an actual programme on your computer, you've a certain overhead in booting up the browser, configuring a profile etc.
PhantomJS is much faster at this (I've seen tests run in less than 1/3 the time). The only trade-off is that you cannot see your tests running, though that's not much of an issue for an automated suite! You could also take screenshots if needed (e.g. on failures). If you really wanted to, you could take screenshots at 24fps & send to ffmpeg to render out a video of your tests, though you may undermine your speed savings then :)
This is a common misunderstanding. Spending some time with the documentation usually clears the confusion. For example, PhantomJS is often used as a headless test runner for tests written in dozens of frameworks: Buster.JS, Capybara, Mocha, Jasmine, QUnit, WebDriver, YUI Test, and many more. As you can see here, PhantomJS does not replace those frameworks at all.
Of course, there are many other uses of PhantomJS, everything from programmatically capture web page to automated network monitoring. There is a list of various blog posts and articles which demonstrate different reported use cases of PhantomJS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With