Search in sources :

Example 21 with WebDriver

use of org.openqa.selenium.WebDriver in project ghostdriver by detro.

the class ScriptExecutionTest method shouldBeAbleToPassMultipleArgumentsToAsyncScripts.

@Test
public void shouldBeAbleToPassMultipleArgumentsToAsyncScripts() {
    WebDriver d = getDriver();
    d.manage().timeouts().setScriptTimeout(0, TimeUnit.MILLISECONDS);
    d.get("http://www.google.com/");
    Number result = (Number) ((JavascriptExecutor) d).executeAsyncScript("arguments[arguments.length - 1](arguments[0] + arguments[1]);", 1, 2);
    assertEquals(3, result.intValue());
    // 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) Test(org.junit.Test)

Example 22 with WebDriver

use of org.openqa.selenium.WebDriver in project ghostdriver by detro.

the class SessionBasicTest method closeShouldNotTerminatePhantomJSProcess.

@Test(expected = NoSuchWindowException.class)
public void closeShouldNotTerminatePhantomJSProcess() throws MalformedURLException {
    // By default, 1 window is created when Driver is launched
    WebDriver d = getDriver();
    assertEquals(1, d.getWindowHandles().size());
    // Check the number of windows
    d.navigate().to("about:blank");
    assertEquals(1, d.getWindowHandles().size());
    // Create a new window
    ((JavascriptExecutor) d).executeScript("window.open('http://www.google.com','google');");
    assertEquals(2, d.getWindowHandles().size());
    // Close 1 window and check that 1 is left
    d.close();
    assertEquals(1, d.getWindowHandles().size());
    // Switch to that window
    d.switchTo().window("google");
    assertNotNull(d.getWindowHandle());
    // Close the remaining window and check now there are no windows available
    d.close();
    assertEquals(0, d.getWindowHandles().size());
    // This should throw a "NoSuchWindowException": the Driver is still running, but no Session/Window are left
    d.getWindowHandle();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Test(org.junit.Test)

Example 23 with WebDriver

use of org.openqa.selenium.WebDriver in project ghostdriver by detro.

the class TimeoutSettingTest method navigateAroundMDN.

@Test
public void navigateAroundMDN() {
    WebDriver d = getDriver();
    d.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    d.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
    d.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test)

Example 24 with WebDriver

use of org.openqa.selenium.WebDriver in project ghostdriver by detro.

the class ElementJQueryEventsTest method shouldBeAbleToClickAndEventsBubbleUpUsingJquery.

@Test
public void shouldBeAbleToClickAndEventsBubbleUpUsingJquery() {
    final String buttonId = "clickme";
    server.setHttpHandler("GET", new HttpRequestCallback() {

        @Override
        public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
            res.getOutputStream().println("<html>\n" + "<head>\n" + "<script src=\"//ajax.googleapis.com/ajax/libs/jquery/" + mJqueryVersion + "/jquery.min.js\"></script>\n" + "<script type=\"text/javascript\">\n" + "   var clicked = false;" + "   $(document).ready(function() {" + "       $('#" + buttonId + "').bind('click', function(e) {" + "           clicked = true;" + "       });" + "   });\n" + "</script>\n" + "</head>\n" + "<body>\n" + "    <a href='#' id='" + buttonId + "'>click me</a>\n" + "</body>\n" + "</html>");
        }
    });
    WebDriver d = getDriver();
    d.get(server.getBaseUrl());
    // Click on the link inside the page
    d.findElement(By.id(buttonId)).click();
    // Check element was clicked as expected
    assertTrue((Boolean) ((JavascriptExecutor) d).executeScript("return clicked;"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebDriver(org.openqa.selenium.WebDriver) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) HttpRequestCallback(ghostdriver.server.HttpRequestCallback) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 25 with WebDriver

use of org.openqa.selenium.WebDriver in project ghostdriver by detro.

the class ElementMethodsTest method checkClickOnAHREFCausesPageLoad.

@Test
public void checkClickOnAHREFCausesPageLoad() {
    WebDriver d = getDriver();
    d.get("http://www.google.com");
    WebElement link = d.findElement(By.cssSelector("a[href=\"/intl/en/ads/\"]"));
    link.click();
    assertTrue(d.getTitle().contains("Ads"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) 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