×

Top 15 PhantomJS Interview Question for 2024

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?

PhantomJS called as headless browser because it execution does not happen on browser which means there is no involvement of browser while executing JavaScript code, it takes over terminal.

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:
    1. cookiesEnabled: It check whether cookie are enable or not. It return true for yes otherwise false. Its default value is true.
Syntax:
  1. phantom.cookiesEnabled
    1. 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.
Syntax:
  1. phantom.cookies
    1. libraryPath: It store the script path which are used by injectJs function.
Syntax:
  1. phantom.libraryPath
    1. 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).
Syntax:
  1. phantom.version
    1. scriptName: It is used to get current script name (this property has depreciated).
Syntax:
  1. phantom.scriptName
    1. args: It contain the script name as its first element (this property has removed).
Syntax:
  1. phantom.args

5) Name some method of PhantomJS.

Following methods are helping us to execute JavaScript without the browser:
    1. addCookie: This method is used for adding cookies in CookieJar. If successfully added it return true otherwise false.
phantom.addCookie({  

    'name' : 'Cookie name',  

    'value' : 'Cookie value',  

    'domain' : 'localhost'  

});
    1. clearCookies: This method used to delete all the cookies from Cookiejar.
  1. phantom.clearCookies();
    1. deleteCookie: It is used for deleting cookie from Cookiejar by using 'name' property
matching chookieName.  

phantom.deleteCookie('Cookie name');
    1. 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'.  

if(condation){  

    phantom.exit(1);  

}else{  

phantom.exit(0):  

}
    1. 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);  

consol.log(addSuccess);  

phantom.exit();

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:
canGoBack

canGoForward

clipRect

Content

Cookies

customHeaders

Even

focusedFrameName

frameContent

frameName
etc.

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:
addCookie()

clearCookies()

deleteCookie()

getPage()

goBack()

goForword()

go()

includes()

injectJs()

childFramesCount()

childFramesName()

currentFrameName()
etc.

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();  

page.open(‘website_url’,function(status){  

page.render(‘imagename.png’);  

phantom.exit();  

});

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?

REPL is stands for Read Eval Print Loop. In PhantomJS, REPL is an interactive mode to test the JavaScript code.

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:
Framework Test Runner
Capybara Poltergeit, Terminus
Buster.JS built-in
Mocha Chutzpah, mocha-phantoms
Jasmine Chutzpah, grunt-contrib-jasmine
Hiro built-in
WebDriver GhostDriver

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.

Related Topics

Polymer.js Interview Questions

1) What is Polymer.js? Polymer.js is an open source JavaScript library. It is developed by Google. It is used to develop web applications for using of web components like HTML. 2) Describe...

3 minutes read.

Top 30 Core Java Interview Questions for 2024

1. What is the difference between HashMap and Hashtable in Java? Ans. S.No. HashMap Hashtable 1. ...

6 minutes read.

Top 12 Docker Interview Questions for 2024

Most frequently asked Docker Interview Questions and Answers for Fresher 1. What is Docker? Docker is a new form of Software Containerization in the field of IT. It is an open-source container...

4 minutes read.

Top 25 jQuery Interview Questions for 2024

Most Frequently asked jQuery Interview Questions and Answers for Fresher and Experienced 1) Define Find and Children Method? In DOM tree if you have to find all the method we use Find...

4 minutes read.

Top 15 Struts Interview Questions for 2024

1) What are the Features of Struts 2? Features of Struts 2 are: Configurable MVC components POJO based actions AJAX support Integration support Various Result Types Various Tag support Theme and...

3 minutes read.

Top 31 Koa Interview Questions for 2024

1) What is Koa? Koa is a very small framework which provides us a minimal interface to build our applications. It is quite flexible and there are numerous modules available on...

4 minutes read.

Top 30 Web Service Interview Questions for 2024

1) What is a Web Service? Web service is a client server application or component. It is used for communication. It is way to communicate between two devices over network. In another word...

5 minutes read.

Top 15 Bootstrap Interview Questions for 2024

1) Explain what is Bootstrap? It is a Framework which is used for building the web application with minimal effort. Bootstrap is also used for developing responsive, mobile-first web sites. 2) What...

10 minutes read.

Top 15 AWS Interview Questions for 2024

1) What is AWS? AWS stands for Amazon Web Services. It is a cloud web hosting platform that offers flexible, scalable, reliable, easy-to-use, and cost-effective solutions. 2) What is Cloud Computing? It is...

2 minutes read.

Top 25 Android Interview Questions for 2024

1) What is Android? It is a software package and open-source operating system that is used in mobile devices. It is also a Linux kernel-based system operating system and application executes within...

3 minutes read.

W3.CSS Interview Questions

1) What is W3.CSS? W3.CSS stands for Cascading Style Sheet. It is developed by w3schools.com. It is used to create faster, beautiful and responsive websites. 2) What are the features of W3.CSS? W3.CSS...

3 minutes read.

WebSockets Interview Questions

1) What is Web Sockets? Web Sockets is a two way communication between the clients and the servers. Here, the clients and servers both the parties can communicate and exchange data...

3 minutes read.

Top 30 Magento Interview Questions for 2024

1) What is Magento? Magento is an open-source content management system. It is used to create e-commerce websites. It is developed by Varien ,Inc, a US private company headquartered in Culver City, California. It...

5 minutes read.

Top 15 Java BeanUtils Interview Questions for 2024

1) What is Java BeanUtils? Java BeanUtils is a design pattern component of the Apache Commons. It facilitates architecture for Java language which is derived from JavaAPI. It helps to set...

3 minutes read.

Top 14 Apache Presto Interview Questions for 2024

1) What is Presto? Presto is a distributed SQL query engine. It is an open source software project to develop a database. 2) What are the features of Presto? There are following features...

2 minutes read.

Top 15 Apache Tapestry Interview Questions for 2024

1) What is Apache Tapestry? It is an open source web framework written in Java and can work under any application server. It is easily integrate with back ends like Hibernate...

2 minutes read.

Top 30 SQLite Interview Question for 2024

1) What is SQLite? It is an in-process library which implements self-contained, serverless, zero-configuration, transactional SQL database. 2) What datatype does SQLite supports? It uses dynamic typing and data can be stored in...

5 minutes read.

Symfony PHP Framework Interview Questions

1) What is Symfony? Symfony is an open source, web application framework. It is written in PHP and used to design PHP applications. It was first released on18 October, 2005. 2) What...

5 minutes read.

Top 16 Groovy interview Questions for 2024

1) What is Groovy? Groovy is an object oriented programming language. It is based on java platform. It can also be used as scripting language. 2) Who designed the Groovy? James Strachan designed...

2 minutes read.

VB.NET Interview Questions

1) What is VB.NET? VB.NET stands for Visual Basic .NET. It is an object oriented programming language. It is implemented on .NET framework and launched by Microsoft in 2001. 2) Who is...

3 minutes read.