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 in headless mode, as shown in the following code example:
package com.secookbook.examples.chapter13; import static org.junit.Assert.*; import static org.testng...