import com.sun.jna.platform.FileUtils; import org.junit.Test; import org.openqa.selenium.*; import org.openqa.selenium.Proxy.ProxyType; import org.openqa.selenium.phantomjs.PhantomJSDriver; import org.openqa.selenium.phantomjs.PhantomJSDriverService; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ThreadGuard; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.Assert; import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.List; import static com.sun.jna.platform.FileUtils.*; import static org.apache.commons.io.FileUtils.copyFile; public class MavenTest { @Test public void testSearchReturnsResults() throws InterruptedException { //Create instance of PhantomJS driver DesiredCapabilities desiredCapabilities = DesiredCapabilities.phantomjs(); SocketAddress addr = new InetSocketAddress("proxy.tcs.com", 8080); Proxy proxy = new Proxy(); proxy.setHttpProxy("proxy.tcs.com"); proxy.setProxyType(ProxyType.MANUAL); PhantomJSDriverService service = new PhantomJSDriverService.Builder() .usingPhantomJSExecutable(new File("D:\\Softwares\\phantomjs\\bin\\phantomjs.exe")) .usingAnyFreePort() .withProxy(proxy) .build(); desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--web-security=no", "--ignore-ssl-errors=yes", "--ssl-protocol=tlsv1"}); // desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, proxy); PhantomJSDriver driver = new PhantomJSDriver(service,desiredCapabilities); //Navigate to the page. WebDriverWait wait = new WebDriverWait(driver, 3000); String url = "http://www.google.com"; driver.get(url); Thread.sleep(3000); String title = driver.getCurrentUrl(); System.out.println("title = "+title); File scrFile = driver.getScreenshotAs(OutputType.FILE); try { copyFile(scrFile, new File("c:\\tmp\\screenshot.png")); } catch (IOException e) { e.printStackTrace(); } // wait.until(ExpectedConditions.presenceOfElementLocated(By.id("hplogo"))); driver.findElementByXPath(".//*[@id='hplogo']"); try { copyFile(scrFile, new File("c:\\tmp\\screenshot.png")); } catch (IOException e) { e.printStackTrace(); } } }