I'm trying to install PhantomJS on my Mac (Yosemite). I did the following: npm install phantomjs Then I did: npm install phantomjs-prebuilt Both of which appear in my nodemodules. But when I try to run phantomjs -versionI get -bash: phantomjs: command not found Also tried installing the binary from the downloads website, but nothing. The logo commonly used to pictorially refer to PhantomJS is a fluorescent blue ghost atop a black background. This refers to the lack of graphical user interface, or main body of the browser, making PhantomJS users seem like ghosts. In March 2018, the development of PhantomJS was suspended due to lack of active contributions. PhantomJS usage. Which version of PhantomJS are you using? Tip: run phantomjs -version. PhantomJS 1.9.8 for Mac What steps will reproduce the problem? Install macOS Sierra Download and unpack https://bitbucket.org. PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 0 of 0 ERROR (0.274 secs / 0 secs) Chrome 53.0.2785 (Mac OS X 10.10.4) ERROR Uncaught ReferenceError: require is not defined.
PhantomJS by itself has many features as website testing, it allow you to run functional tests with frameworks such as Jasmine, QUnit, Mocha, Capybara, WebDriver, and many others. It allow you to create screen captures, website automatization, manipulation of the document and network monitoring etc.
In this article we'll learn how to manipulate PhantomJS from the command line in Windows and test basic features as screenshots, PDF generation etc.
Note: there's no installation process as you'll get
.zip file with two folder, examples and bin (which contains phantomjs.exe).
Imagine a simple web browser like Google Chrome, ready? Now remove the Graphic User Interface (GUI) and you'll get a headless browser, that's basically PhantomJS. They're great for automating and testing web pages programmatically and PhantomJS is one of the best available headless browsers.
After the extraction of the download .zip file you'll get 2 folders : examples and bin. Blue cats for sale. In Bin is located the executable of PhantomJS.
First, open the windows terminal cmd.exe and navigate to the bin path of phantomJS executing the following command:
Note: you can simply create an environment variable pointing to the location of Phantomjs.exe and the execute it from wherever you are in the console.
Now that you're located in the path of PhantomJS you'll be able to execute commands easily with phantomjs.
For your first exercise, we'll take a screenshot of Our Code World website. Create a
screenshot.js file in the same location of the phantomjs executable :
And include the following code in the
Finally execute the following command in the command prompt :
Wait till is executed see the success message, and open the bin folder again.
Our Screenshot of the website has been created, awesome and really easy isn't ?.
If the data is not transferred correctly, check if the network works as expected.
Specifically on Windows, the default proxy setting may cause a massive network latency. The workaround is to disable proxy completely, e.g. by launching PhantomJS with
--proxy-type=none command-line argument.
Now that you know how does PhantomJS basically works, you'll be able to understand the documentation and discover all the awesome features that PhantomJS has to offer.
As always, we encourage you to check out the documentation to learn how to generate even PDF's, remote debuggin etc. Have fun !