1) What is PhantomJS?
PhantomJS is a lightweight headless scripted browser built on WebKit. It is used for automation web page interaction.
2) Why it is called as headless browser?
3) What is WebKit?
WebKit is software component used for rendering web pages in web browsers (Chrome, Safari as well as other).
4) What are the objects in PhantomJS.
These are the following objects in PhantomJs:
- cookiesEnabled: It check whether cookie are enable or not. It return true for yes otherwise false. Its default value is true.
- cookies: It is used to get or set cookies from domain which are stored in Cookiejar. Cookie returns an object with all cookies available for the domain.
- libraryPath: It store the script path which are used by injectJs function.
- version: It is a read-only property which return version of PhantomJS instance which are running. The details are return in an object ('major': 1,'minor': 7, 'patch': 0).
- scriptName: It is used to get current script name (this property has depreciated).
- args: It contain the script name as its first element (this property has removed).
5) Name some method of PhantomJS.
- addCookie: This method is used for adding cookies in CookieJar. If successfully added it return true otherwise false.
'name' : 'Cookie name',
'value' : 'Cookie value',
'domain' : 'localhost'
- clearCookies: This method used to delete all the cookies from Cookiejar.
- deleteCookie: It is used for deleting cookie from Cookiejar by using 'name' property
- exit: This method exit the program when return specific return value. It there is no specific return value it return '0'.
specific return value it return '0'.
- injectJs: It injects external file from specified file into phantom. If file does not found in current directory, then libraryPath property of Phantos is used as an additional place to track the path.
var addSuccess= phantom.injectJs(filename);
6) What is webpage module property? Name some of them.
Webpage module property provides a facility to interact with contents inside a webpage.
Some module properties are:
7) What is webpage module method? Name some of them.
Webpage module keeps the method for Cookies, Frames, Page Navigation, Reload, Rendering and Uploading of Files.
Some webpage module methods are:
8) What do you understand about screen capture?
PhantomJs provide facility capture screenshot of web page. This capture image can be saved in different formate such as .png, .jpeg, .pdf, .gif. It is also able to convert as PDF.
Following script show the simple way for screen capture.
var page = require(‘webpage’).create();
9) How network monitoring is done in PhantomJS?
Natwork monitoring is done by using events such as onResourceRequested
and DOM manipulation
. This helps in monitoring the traffic for given page.
10) What is page automation?
Manipulating and loading of web pages and performing operation such as DOM manipulation by clicking buttons, etc.
11) Is PhantomJS support command line interface (CLI) execution?
Yes, PhantomJS support command line interface execution. CLI execution is done by using keyword "phantomjs" with file name. For example: "phantomjs filename.js".
12) What is the role of child process module in PhantomJS?
Child process module helps to interact with sub processes using stdin /stdout/ stderr
. Child processes can be used for performing task like invoke programs, printing, or to sending mail.
13) What is REPL?
is stands for Read Eval Print Loop
14) How testing are done in PhantomJS?
PhantomJS is not a test framework. PhantomJS use different libraries known as test runner for testing.
Some of the framework along with their test runner is:
15) What is file system module in PhantomJS?
File system module perform operations on files and directories. We can create, write and delete a files and directory.
There are two properties in file system module:
Separator: It is used for file paths (for windows: \, for linux: /).
Working Directory: It is a directory in which PhantomJS executes.