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);
}
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;");
}
});
}
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();
}
Aggregations