use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class ElementMethodsTest method shouldUsePageTimeoutToWaitForPageLoadOnInput.
@Test
public void shouldUsePageTimeoutToWaitForPageLoadOnInput() throws InterruptedException {
WebDriver d = getDriver();
String inputString = "clicking";
d.get("http://www.duckduckgo.com");
WebElement textInput = d.findElement(By.cssSelector("#search_form_input_homepage"));
assertFalse(d.getTitle().contains(inputString));
textInput.click();
assertFalse(d.getTitle().contains(inputString));
// This input will ALSO submit the search form, causing a Page Load
textInput.sendKeys(inputString + "\n");
assertTrue(d.getTitle().contains(inputString));
}
use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class AuthBasicTest method simpleBasicAuthShouldWork.
@Test
public void simpleBasicAuthShouldWork() {
// Get Driver Instance
WebDriver driver = getDriver();
// wrong password
driver.get(String.format("http://httpbin.org/basic-auth/%s/Wrong%s", userName, password));
assertTrue(!driver.getPageSource().contains("authenticated"));
// we should be authorized
driver.get(String.format("http://httpbin.org/basic-auth/%s/%s", userName, password));
assertTrue(driver.getPageSource().contains("authenticated"));
}
use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class CookieTest method shouldBeAbleToCreateCookieViaJavascriptOnGoogle.
@Test
public void shouldBeAbleToCreateCookieViaJavascriptOnGoogle() {
String ckey = "cookiekey";
String cval = "cookieval";
WebDriver d = getDriver();
d.get("http://www.google.com");
JavascriptExecutor js = (JavascriptExecutor) d;
// Of course, no cookie yet(!)
Cookie c = d.manage().getCookieNamed(ckey);
assertNull(c);
// Attempt to create cookie on multiple Google domains
js.executeScript("javascript:(" + "function() {" + " cook = document.cookie;" + " begin = cook.indexOf('" + ckey + "=');" + " var val;" + " if (begin !== -1) {" + " var end = cook.indexOf(\";\",begin);" + " if (end === -1)" + " end=cook.length;" + " val=cook.substring(begin+11,end);" + " }" + " val = ['" + cval + "'];" + " if (val) {" + " var d=Array('com','co.jp','ca','fr','de','co.uk','it','es','com.br');" + " for (var i = 0; i < d.length; i++) {" + " document.cookie = '" + ckey + "='+val+';path=/;domain=.google.'+d[i]+'; ';" + " }" + " }" + "})();");
c = d.manage().getCookieNamed(ckey);
assertNotNull(c);
assertEquals(cval, c.getValue());
// Set cookie as empty
js.executeScript("javascript:(" + "function() {" + " var d = Array('com','co.jp','ca','fr','de','co.uk','it','cn','es','com.br');" + " for(var i = 0; i < d.length; i++) {" + " document.cookie='" + ckey + "=;path=/;domain=.google.'+d[i]+'; ';" + " }" + "})();");
c = d.manage().getCookieNamed(ckey);
assertNotNull(c);
assertEquals("", c.getValue());
}
use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class CookieTest method shouldThrowExceptionIfAddingCookieBeforeLoadingAnyUrl.
@Test(expected = Exception.class)
public void shouldThrowExceptionIfAddingCookieBeforeLoadingAnyUrl() {
// NOTE: At the time of writing, this test doesn't pass with FirefoxDriver.
// ChromeDriver is fine instead.
//< detro: I buy you a beer if you guess what am I quoting here
String xval = "123456789101112";
WebDriver d = getDriver();
// Set cookie, without opening any page: should throw an exception
d.manage().addCookie(new Cookie("x", xval));
}
use of org.openqa.selenium.WebDriver in project ghostdriver by detro.
the class DirectFileUploadTest method checkFileUploadCompletes.
@Test
public void checkFileUploadCompletes() throws IOException {
WebDriver d = getDriver();
if (!(d instanceof PhantomJSDriver)) {
// The command under test is only available when using PhantomJS
return;
}
PhantomJSDriver phantom = (PhantomJSDriver) d;
String buttonId = "upload";
// Create the test file for uploading
File testFile = File.createTempFile("webdriver", "tmp");
testFile.deleteOnExit();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(testFile.getAbsolutePath()), "utf-8"));
writer.write(FILE_HTML);
writer.close();
server.setHttpHandler("POST", new HttpRequestCallback() {
@Override
public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
if (ServletFileUpload.isMultipartContent(req) && req.getPathInfo().endsWith("/upload")) {
// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory(1024, new File(System.getProperty("java.io.tmpdir")));
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
List<FileItem> items;
try {
items = upload.parseRequest(req);
} catch (FileUploadException fue) {
throw new IOException(fue);
}
res.setHeader("Content-Type", "text/html; charset=UTF-8");
InputStream is = items.get(0).getInputStream();
OutputStream os = res.getOutputStream();
IOUtils.copy(is, os);
os.write("<script>window.top.window.onUploadDone();</script>".getBytes());
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
return;
}
res.sendError(400);
}
});
// Upload the temp file
phantom.get(server.getBaseUrl() + "/common/upload.html");
phantom.executePhantomJS("var page = this; page.uploadFile('input#" + buttonId + "', '" + testFile.getAbsolutePath() + "');");
phantom.findElement(By.id("go")).submit();
// Uploading files across a network may take a while, even if they're really small.
// Wait for the loading label to disappear.
WebDriverWait wait = new WebDriverWait(phantom, 10);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("upload_label")));
phantom.switchTo().frame("upload_target");
wait = new WebDriverWait(phantom, 5);
wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//body"), LOREM_IPSUM_TEXT));
// Navigate after file upload to verify callbacks are properly released.
phantom.get("http://www.google.com/");
}
Aggregations