Search in sources :

Example 96 with WebDriver

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

the class FileUploadTest method checkFileUploadFailsIfFileDoesNotExist.

@Test
public void checkFileUploadFailsIfFileDoesNotExist() throws InterruptedException {
    WebDriver d = getDriver();
    // Trying to upload a file that doesn't exist
    d.get(server.getBaseUrl() + "/common/upload.html");
    d.findElement(By.id("upload")).sendKeys("file_that_does_not_exist.fake");
    d.findElement(By.id("go")).submit();
    // Uploading files across a network may take a while, even if they're really small.
    // Wait for a while and make sure the "upload_label" is still there: means that the file was not uploaded
    Thread.sleep(1000);
    assertTrue(d.findElement(By.id("upload_label")).isDisplayed());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test)

Example 97 with WebDriver

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

the class PhantomJSCommandTest method executePhantomJS.

@Test
public void executePhantomJS() {
    WebDriver d = getDriver();
    if (!(d instanceof PhantomJSDriver)) {
        // The command under test is only available when using PhantomJS
        return;
    }
    PhantomJSDriver phantom = (PhantomJSDriver) d;
    // Do we get results back?
    Object result = phantom.executePhantomJS("return 1 + 1");
    assertEquals(new Long(2), (Long) result);
    // Can we read arguments?
    result = phantom.executePhantomJS("return arguments[0] + arguments[0]", new Long(1));
    assertEquals(new Long(2), (Long) result);
    // Can we override some browser JavaScript functions in the page context?
    result = phantom.executePhantomJS("var page = this;" + "page.onInitialized = function () { " + "page.evaluate(function () { " + "Math.random = function() { return 42 / 100 } " + "})" + "}");
    phantom.get("http://ariya.github.com/js/random/");
    WebElement numbers = phantom.findElement(By.id("numbers"));
    boolean foundAtLeastOne = false;
    for (String number : numbers.getText().split(" ")) {
        foundAtLeastOne = true;
        assertEquals("42", number);
    }
    assert (foundAtLeastOne);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 98 with WebDriver

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

the class RuntimeProxySetupTest method requestsProcessedByProxy.

@Test
public void requestsProcessedByProxy() {
    proxy.newHar(url.toString());
    WebDriver driver = getDriver();
    driver.navigate().to(url);
    JsonObject har = proxy.har();
    assertNotNull(har);
    String firstUrlLoaded = har.getAsJsonObject("log").getAsJsonArray("entries").get(0).getAsJsonObject().getAsJsonObject("request").getAsJsonPrimitive("url").getAsString();
    assertEquals(url.toString(), firstUrlLoaded);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) JsonObject(com.google.gson.JsonObject)

Example 99 with WebDriver

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

the class ScriptExecutionTest method shouldBeAbleToExecuteMultipleAsyncScriptsSequentially.

@Test
public void shouldBeAbleToExecuteMultipleAsyncScriptsSequentially() {
    WebDriver d = getDriver();
    d.manage().timeouts().setScriptTimeout(0, TimeUnit.MILLISECONDS);
    d.get("http://www.google.com/");
    Number numericResult = (Number) ((JavascriptExecutor) d).executeAsyncScript("arguments[arguments.length - 1](123);");
    assertEquals(123, numericResult.intValue());
    String stringResult = (String) ((JavascriptExecutor) d).executeAsyncScript("arguments[arguments.length - 1]('abc');");
    assertEquals("abc", stringResult);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test)

Example 100 with WebDriver

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

the class ScriptExecutionTest method findGoogleInputFieldInjectingJavascript.

@Test
public void findGoogleInputFieldInjectingJavascript() {
    WebDriver d = getDriver();
    d.get("http://www.google.com");
    WebElement e = (WebElement) ((JavascriptExecutor) d).executeScript("return document.querySelector(\"[name='\"+arguments[0]+\"']\");", "q");
    assertNotNull(e);
    assertEquals("input", e.getTagName().toLowerCase());
}
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