use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class WindowHandlesTest method openPopupAndGetCurrentUrl.
@Test
public void openPopupAndGetCurrentUrl() throws InterruptedException {
server.setHttpHandler("GET", new HttpRequestCallback() {
@Override
public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
res.getOutputStream().println("<html>" + "<head>" + "<script language=\"javascript\" type=\"text/javascript\">\n" + "function openProjectPopup(url) {\n" + " var popWidth = 1024;\n" + " var leftX = (screen.width) ? (screen.width-popWidth)/2 : 0;\n" + " var height = screen.availHeight;\n" + " var win = window.open(url, \"projectPopup\", \"left=\"+leftX+\",top=0,width=\"+popWidth+\",height=\"+height+\",location=yes,menubar=no,resizable=yes,status=no,scrollbars=yes\");\n" + " win.location.href='http://www.jnto.go.jp/'; //put a link to a slow loading webpage here\n" + " win.focus();\n" + "}\n" + "</script>\n" + "</head>\n" + " <body>\n" + " <a href=\"popup.htm\" onclick=\"return openProjectPopup('popup.htm')\">Link to popup</a>" + " </body>\n" + "</html>");
}
});
// Load page
WebDriver d = getDriver();
d.get(server.getBaseUrl());
// Click on link that will cause popup to be created
d.findElement(By.xpath("//a")).click();
// Switch to new popup
String popupHandle = (String) d.getWindowHandles().toArray()[1];
d.switchTo().window(popupHandle);
assertTrue(d.getTitle().contains("Japan"));
}
use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class WindowSizingAndPositioningTest method manipulateWindowMaximize.
@Test
public void manipulateWindowMaximize() {
WebDriver d = getDriver();
d.get("http://www.google.com");
Dimension sizeBefore = d.manage().window().getSize();
d.manage().window().maximize();
Dimension sizeAfter = d.manage().window().getSize();
assertTrue(sizeBefore.width <= sizeAfter.width);
assertTrue(sizeBefore.height <= sizeAfter.height);
}
use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class WindowSizingAndPositioningTest method manipulateWindowPosition.
@Test
public void manipulateWindowPosition() {
WebDriver d = getDriver();
d.get("http://www.google.com");
assertTrue(d.manage().window().getPosition().x >= 0);
assertTrue(d.manage().window().getPosition().y >= 0);
d.manage().window().setPosition(new Point(0, 0));
assertTrue(d.manage().window().getPosition().x == 0);
assertTrue(d.manage().window().getPosition().y == 0);
}
use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class GoogleSearchTest method searchForCheese.
@Test
public void searchForCheese() {
String strToSearchFor = "Cheese!";
WebDriver d = getDriver();
// Load Google.com
d.get(" http://www.google.com");
// Locate the Search field on the Google page
WebElement element = d.findElement(By.name("q"));
// Type Cheese
element.sendKeys(strToSearchFor);
// Submit form
element.submit();
// Check results contains the term we searched for
assertTrue(d.getTitle().toLowerCase().contains(strToSearchFor.toLowerCase()));
}
use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class IsolatedSessionTest method createSession.
@Before
public void createSession() throws Exception {
disableAutoQuitDriver();
// Create first Driver, and grab it's cookies
WebDriver d = getDriver();
d.get(url + "?session1=value1");
// Grab set of session cookies
firstSessionCookies = d.manage().getCookies();
// Manually quit the current Driver and create a new one
d.quit();
// Create second Driver, and grab it's cookies
prepareDriver();
d = getDriver();
d.get(url + "?session2=value2");
// Grab set of session cookies
secondSessionCookies = d.manage().getCookies();
// Manually quit the current Driver and create a new one
d.quit();
}
Aggregations