Running tests in headless mode with PhantomJS
PhantomJS is a headless Webkit-based browser. We can use PhantomJS in conjunction with Selenium WebDriver to run basic functional tests.
In this recipe, we will set up and use PhantomJS to run a simple test.
Getting ready
You will need PhantomJS binary for this example. You can download the appropriate binary from http://phantomjs.org/.
In this example, the Windows version of PhantomJS is used.
You will also need to add a dependency in the maven pom.xml
file, as follows:
<dependency> <groupId>com.github.detro</groupId> <artifactId>phantomjsdriver</artifactId> <version>1.2.0</version> <scope>test</scope> </dependency>
How to do it...
Let's create a new test PhantomjsTest
that uses PhantomJS to run a test ...
Get Selenium Testing Tools Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.