Hi Bhanu, you can run test cases in headless mode using Phantom JS by following this piece of code:
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
public class WebDriverBase {
static protected WebDriver driver;
public static void setup() {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true); // not really needed: JS enabled by default
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "src/test/resources/phantomjs");
driver = new PhantomJSDriver(caps);
}
public static void main(String[] args) {
WebDriverBase.setup();
driver.get("https://www.facebook.com");
}
}
You will also need the ghost driver dependency as well:
<dependency>
<groupId>com.github.detro.ghostdriver</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.0.1</version>
</dependency>