automation testing using phantom js and selenium webdriver with screenshot

– Download latest version of selenium, I am using 2.45.0
– Download latest version of PhantomJs, I am using 2.0- windows, extract to a safe path.

Use below code to automate with phantomjs (Headless browser)

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.phantomjs.PhantomJSDriver;

public class Phantom {

@Test
public void phantomTest() throws IOException {
File file = new File(
"F:\\work\\phantomjs\\phantomjs-2.0.0-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
PhantomJSDriver driver = new PhantomJSDriver();
driver.get("https://gmail.com");
driver.manage().window().maximize();
File tempfile = driver.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(tempfile, new File(
"F:\\work\\phantomjs\\screenshot.png"));
driver.quit();
}
}

No images available.