Search in sources :

Example 6 with WebDriver

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"));
}
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 7 with WebDriver

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

Example 8 with WebDriver

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

Example 9 with WebDriver

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

Example 10 with WebDriver

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

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