use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class ElementMethodsTest method shouldWaitForOnClickCallbackToFinishBeforeContinuing.
@Test
public void shouldWaitForOnClickCallbackToFinishBeforeContinuing() {
server.setHttpHandler("GET", new HttpRequestCallback() {
@Override
public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
res.getOutputStream().println("<script type=\"text/javascript\">\n" + " function sleep(milliseconds) {\n" + " var start = new Date().getTime();\n" + " for (;;) {\n" + " if ((new Date().getTime() - start) > milliseconds){\n" + " break;\n" + " }\n" + " }\n" + " } \n" + " function myFunction() {\n" + " sleep(1000)\n" + " window.location.href = 'http://www.google.com';\n" + " }\n" + " </script>\n" + " <a onclick=\"javascript: myFunction();\">Click Here</a>");
}
});
WebDriver d = getDriver();
d.get(server.getBaseUrl());
d.findElement(By.xpath("html/body/a")).click();
assertTrue(d.getTitle().toLowerCase().contains("google"));
}
use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class FileUploadTest method checkUploadingTheSameFileMultipleTimes.
@Test
public void checkUploadingTheSameFileMultipleTimes() throws IOException {
WebDriver d = getDriver();
File file = File.createTempFile("test", "txt");
file.deleteOnExit();
d.get(server.getBaseUrl() + "/common/formPage.html");
WebElement uploadElement = d.findElement(By.id("upload"));
uploadElement.sendKeys(file.getAbsolutePath());
uploadElement.submit();
d.get(server.getBaseUrl() + "/common/formPage.html");
uploadElement = d.findElement(By.id("upload"));
uploadElement.sendKeys(file.getAbsolutePath());
uploadElement.submit();
}
use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class NavigationTest method navigateToNameJet.
@Test
public void navigateToNameJet() {
// NOTE: This passes only when the User Agent is NOT PhantomJS {@see setUserAgentForPhantomJSDriver}
// method above.
WebDriver d = getDriver();
d.navigate().to("http://www.namejet.com/");
}
use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class ScriptExecutionTest method setTimeoutAsynchronously.
@Test
public void setTimeoutAsynchronously() {
WebDriver d = getDriver();
d.get("http://www.google.com");
String res = (String) ((JavascriptExecutor) d).executeAsyncScript("window.setTimeout(arguments[arguments.length - 1], arguments[0], 'done');", 1000);
assertEquals("done", res);
}
use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class ScriptExecutionTest method shouldBeAbleToExecuteMultipleAsyncScriptsSequentiallyWithNavigation.
@Ignore("Known issue #140 - see https://github.com/detro/ghostdriver/issues/140)")
@Test
public void shouldBeAbleToExecuteMultipleAsyncScriptsSequentiallyWithNavigation() {
// NOTE: This test is supposed to fail!
// It's a reminder that there is some internal issue in PhantomJS still to address.
WebDriver d = getDriver();
d.manage().timeouts().setScriptTimeout(0, TimeUnit.MILLISECONDS);
d.get("http://www.google.com/");
Number numericResult = (Number) ((JavascriptExecutor) d).executeAsyncScript("arguments[arguments.length - 1](123);");
assertEquals(123, numericResult.intValue());
d.get("http://www.google.com/");
String stringResult = (String) ((JavascriptExecutor) d).executeAsyncScript("arguments[arguments.length - 1]('abc');");
assertEquals("abc", stringResult);
// Verify that a future navigation does not cause the driver to have problems.
d.get("http://www.google.com/");
}
Aggregations