PhantomJS on MacOS is a quick, excellent alternative to Google Chrome for a native browser testing platform. The beta version, PhantomJS 2.5 offers support for ES2015 unlike the current stable branch (at the time of writing this article 2.1.x).
Download PhantomJS 2.5 for MacOS
At the time of writing this article, the following versions are available:
- Ubuntu 16.04 LTS (xenial)
- Ubuntu 14.04 LTS (trusty)
- MacOS – unsure if works on El-Capitan or Yosemite. Will find a way to verify in the future.
Download the version for your operating system from:
Add PhantomJS to Your Path
You can find the PhantomJS binary under the bin dir of the zip archive. If you have a preferred way of adding items to your path, go ahead and add it. If you don’t have a clue what a path is, then you can follow along below.
- After adding to your path, verify by running
which phantomjsfrom the command line.
- If everything looks good and you see the correct path, add the PHANTOMJS_BIN variable to your environment by typing
export PHANTOMJS_BIN=`which phantomjs`
- NOTE: Notice that my example uses the back-tick character and NOT the single quote mark in the example above!
Add PhantomJS to Your Environment
These instructions are based off of the assumption that you downloaded the PhantomJS zip to your downloads directory.
- Open your terminal and make sure you are in your home dir.
- Move to your new dir
- Move your archive into your folder
cp ~/Downloads/phantomjs-2.5.0-beta-macos.zip ./(make sure you reference the correct file, as you are typing the filename, you can try hitting the tab key for autocomplete)
- Extract your archive
- Rename the extracted dir
mv phantomjs-2.5.0-beta-macos phantomjs
- Move into the extracted phantom dir
- Move into the phantom bin dir
- Add executable permissions
chmod +x phantomjs
- Add to your path
sudo ln -s `pwd`/phantomjs /usr/local/bin
- Test by typing:
phantomjs --version(at this point you should see the version. At the time of this post, 2.5.0-development).
- If the console yells at you with an error about the webp library: /usr/local/lib/libwebp.6.dylib, I posted a solution here: SOLVED: PhantomJS 2.5 Beta: Library not loaded: libwebp.6.dylib
- If you don’t get a version, you may need to add execute permissions. Browse back to your extracted phantom bin dir and type
chmod +x phantomjs. Try checking your PhantomJS version again. If you still don’t see version information, type
source ~/.bash_profileand type
which phantomjs(you should see a path to the phantomjs bin folder)
- After you have verified that you are showing phantomjs 2.5+, you need to add the PHANTOMJS_BIN variable to override other global installations. type:
echo "export PHANTOMJS_BIN=`which phantomjs`" >> ~/.bash_profile
- Close and re-open your terminal or type:
- Verify PHANTOMJS_BIN var:
echo $PHANTOMJS_BIN(you should see the executable path for your phantomjs 2.5).