How to install Phantom in Ubuntu 14

4 min. read

Caution! This article is 7 years old. It may be obsolete or show old techniques. It may also still be relevant, and you may find it useful! So it has been marked as deprecated, just in case.

I recently wanted to try out Phantom as a headless browser for JavaScript tests. Up until now I had been using the Jasmine standalone version in the browser and wanted to check how to run them on a terminal environment so that I can run them in the CI too. Seems like phantomjs might helpt with that!

I first downloaded a tar with a version of Phantom from their official web. I had to check that I had fontconfig or libfontconfig, GLIBCXX_3.4.9 and GLIBC_2.7. Then I copied the files under /opt, which is the path under which I normaly install these things.

It didn't work so I tried also a gist that I found on GitHub.

It didn't work either, so I decided to use the not-recommended way, which is building it from source. It recommends to install the ttf-mscorefonts-installer package, which you can find in synaptics or the Ubuntu Software Center.

For the record, the git clone command took a while, and it downloaded 130MB of files. The git submodule update command took long as well.

In case you want to use it as an npm package, there is phantomjs-prebuilt as well, and a gulp plugin for the combination Jasmine-Phantom.

I moved all the stuff to /opt, then I added this line to my .bashrc (add it to .bash_profile instead if you are in OSX):


export PATH="/opt/phantomjs/bin/:$PATH"

Then you can run it with ./bin/phantom.

Other things I tried

  • I tried the gulp-jasmine-phantom plugin, but for some reason it didn't find the tests.
  • I also installed phantom-jasmine, another npm package, and ran:
    
    phantom-jasmine js/specrunner.html
    phantom-jasmine http://localhost:4000/test/specrunner.html
    
    (specrunner.html is my Jasmine running file) All of them gave me an error, and it made a runner.html file in the local directory.

However, testem with a config file works. Both testem and testem ci work.

The testem ci command generates a Jasmine page for you. So if you want to add divs to the specrunner.html file, you have to tell the testem.json file and then add /testem.js to the specrunner scripts.

If you have to use mock-ajax, jquery and jquery-jasmine, you also have to add those to the testem.json. These days I am not too queen on jQuery anymore, so I don't use it in new projects.

Finally, there is gulp-testem but at the moment of writing this, it's 2 years since the last commit, and it didn't work. It asked for gulp-util. Also I didn't like the server setup in the readme.

Comments