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