Search in sources :

Example 16 with HttpRequestCallback

use of ghostdriver.server.HttpRequestCallback in project ghostdriver by detro.

the class FrameSwitchingTest method shouldBeAbleToSwitchToIFrameThatHasNoNameNorId.

@Test
public void shouldBeAbleToSwitchToIFrameThatHasNoNameNorId() {
    server.setHttpHandler("GET", new HttpRequestCallback() {

        @Override
        public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
            res.getOutputStream().println("<html>" + "<body>" + "   <iframe></iframe>" + "</body>" + "</html>");
        }
    });
    WebDriver d = getDriver();
    d.get(server.getBaseUrl());
    WebElement el = d.findElement(By.tagName("iframe"));
    d.switchTo().frame(el);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpRequestCallback(ghostdriver.server.HttpRequestCallback) GetFixtureHttpRequestCallback(ghostdriver.server.GetFixtureHttpRequestCallback) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with HttpRequestCallback

use of ghostdriver.server.HttpRequestCallback in project ghostdriver by detro.

the class FrameSwitchingTest method shouldTimeoutWhileChangingIframeSource.

@Test(expected = TimeoutException.class)
public void shouldTimeoutWhileChangingIframeSource() {
    final String iFrameId = "iframeId";
    // Define HTTP response for test
    server.setHttpHandler("GET", new HttpRequestCallback() {

        @Override
        public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
            String pathInfo = req.getPathInfo();
            ServletOutputStream out = res.getOutputStream();
            if (pathInfo.endsWith("iframe_content.html")) {
                // nested frame 1
                out.println("iframe content");
            } else {
                // main page
                out.println("<html>\n" + "<body>\n" + "  <iframe id='" + iFrameId + "'></iframe>\n" + "  <script>\n" + "  setTimeout(function() {\n" + "    document.getElementById('" + iFrameId + "').src='iframe_content.html';\n" + "  }, 2000);\n" + "  </script>\n" + "</body>\n" + "</html>");
            }
        }
    });
    // Launch Driver against the above defined server
    WebDriver d = getDriver();
    d.get(server.getBaseUrl());
    // Switch to iframe
    d.switchTo().frame(iFrameId);
    assertEquals(0, d.findElements(By.id(iFrameId)).size());
    assertFalse(d.getPageSource().toLowerCase().contains("iframe content"));
    new WebDriverWait(d, 5).until(new Predicate<WebDriver>() {

        @Override
        public boolean apply(@Nullable WebDriver driver) {
            assertEquals(0, driver.findElements(By.id(iFrameId)).size());
            return (Boolean) ((JavascriptExecutor) driver).executeScript("return false;");
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpRequestCallback(ghostdriver.server.HttpRequestCallback) GetFixtureHttpRequestCallback(ghostdriver.server.GetFixtureHttpRequestCallback) ServletOutputStream(javax.servlet.ServletOutputStream) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 18 with HttpRequestCallback

use of ghostdriver.server.HttpRequestCallback in project ghostdriver by detro.

the class MouseCommandsTest method handleClickWhenOnClickInlineCodeFails.

@Test
public void handleClickWhenOnClickInlineCodeFails() {
    // Define HTTP response for test
    server.setHttpHandler("GET", new HttpRequestCallback() {

        @Override
        public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
            res.getOutputStream().println("<html>" + "<head>" + "<script>\n" + "function functionThatHasErrors() {\n" + "    a.callSomeMethodThatDoesntExist();\n" + "}\n" + "function validFunction() {\n" + "    window.location = 'http://google.com';\n" + "}\n" + "</script>\n" + "</head>" + "<body>" + "\n" + "<a href=\"javascript:;\" onclick=\"validFunction();functionThatHasErrors();\">Click me</a>" + "</body>" + "</html>");
        }
    });
    // Navigate to local server
    WebDriver d = getDriver();
    d.navigate().to(server.getBaseUrl());
    WebElement el = d.findElement(By.linkText("Click me"));
    el.click();
}
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) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Aggregations

HttpRequestCallback (ghostdriver.server.HttpRequestCallback)18 HttpServletRequest (javax.servlet.http.HttpServletRequest)18 HttpServletResponse (javax.servlet.http.HttpServletResponse)18 Test (org.junit.Test)18 IOException (java.io.IOException)16 WebDriver (org.openqa.selenium.WebDriver)8 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)5 GetFixtureHttpRequestCallback (ghostdriver.server.GetFixtureHttpRequestCallback)4 ServletOutputStream (javax.servlet.ServletOutputStream)4 List (java.util.List)2 FileUploadException (org.apache.commons.fileupload.FileUploadException)2 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)2 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)2 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)1 WebElement (org.openqa.selenium.WebElement)1 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)1