Headless testing with PhantomJS

Remember we said back in the introduction, that we could execute Jasmine without the need of a browser window? To do so, we are going to use PhantomJS, a scriptable headless WebKit browser (the same rendering engine of Safari).

Downloading and installing PhantomJS

PhantomJS ships binary distributions to Windows, Mac, and Linux. So to get started is as easy as downloading a zip file and executing the phantomjs command.

Go to the PhantomJS download page available at http://phantomjs.org/download.html and download the appropriate distribution for your platform.

Once downloaded, you can place the executable at the root of the project folder.

Running your tests without opening a browser

With the executable available, we are going to download a small script to allow running the Jasmine specs with PhantomJS.

You can download it from https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js, and place it at the root of the project folder.

Done! Now you can run yours specs in the command line like:

$ phantomjs run-jasmine.js SpecRunner.html

And you will see the result on the console, with no browser window open:

'waitFor()' finished in 493ms.

Passing 60 specs

So now we can run and get the results of the specs right from the console. This will allow some awesome automation as we will see next.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.181.36