Search in sources :

Example 16 with WebDriver

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"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebDriver(org.openqa.selenium.WebDriver) HttpRequestCallback(ghostdriver.server.HttpRequestCallback) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with WebDriver

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();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 18 with WebDriver

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/");
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test)

Example 19 with WebDriver

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);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test)

Example 20 with WebDriver

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/");
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

WebDriver (org.openqa.selenium.WebDriver)167 WebElement (org.openqa.selenium.WebElement)87 Test (org.junit.Test)61 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)59 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)40 Actions (org.openqa.selenium.interactions.Actions)25 IOException (java.io.IOException)12 Cookie (org.openqa.selenium.Cookie)11 List (java.util.List)10 File (java.io.File)9 HttpRequestCallback (ghostdriver.server.HttpRequestCallback)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)8 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)7 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)7 By (org.openqa.selenium.By)5 Dimension (org.openqa.selenium.Dimension)5 Predicate (com.google.common.base.Predicate)4 TimeoutException (org.openqa.selenium.TimeoutException)4