Search in sources :

Example 91 with WebDriver

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

the class DriverBasicTest method useDriverButDontQuit.

@Test
public void useDriverButDontQuit() {
    WebDriver d = getDriver();
    disableAutoQuitDriver();
    d.get("http://www.google.com/");
    d.quit();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test)

Example 92 with WebDriver

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

the class ElementMethodsTest method checkClickOnINPUTSUBMITCausesPageLoad.

@Test
public void checkClickOnINPUTSUBMITCausesPageLoad() {
    WebDriver d = getDriver();
    d.get("http://www.duckduckgo.com");
    WebElement textInput = d.findElement(By.cssSelector("#search_form_input_homepage"));
    WebElement submitInput = d.findElement(By.cssSelector("#search_button_homepage"));
    assertFalse(d.getTitle().contains("clicking"));
    textInput.click();
    assertFalse(d.getTitle().contains("clicking"));
    textInput.sendKeys("clicking");
    assertFalse(d.getTitle().contains("clicking"));
    submitInput.click();
    assertTrue(d.getTitle().contains("clicking"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 93 with WebDriver

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

the class ElementMethodsTest method SubmittingFormShouldFireOnSubmitForThatForm.

@Test
public void SubmittingFormShouldFireOnSubmitForThatForm() {
    WebDriver d = getDriver();
    d.get(server.getBaseUrl() + "/common/javascriptPage.html");
    WebElement formElement = d.findElement(By.id("submitListeningForm"));
    formElement.submit();
    WebDriverWait wait = new WebDriverWait(d, 30);
    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("result"), "form-onsubmit"));
    WebElement result = d.findElement(By.id("result"));
    String text = result.getText();
    boolean conditionMet = text.contains("form-onsubmit");
    assertTrue(conditionMet);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 94 with WebDriver

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

the class FileUploadTest method checkOnChangeEventIsFiredOnFileUpload.

@Test
public void checkOnChangeEventIsFiredOnFileUpload() throws IOException {
    WebDriver d = getDriver();
    d.get(server.getBaseUrl() + "/common/formPage.html");
    WebElement uploadElement = d.findElement(By.id("upload"));
    WebElement result = d.findElement(By.id("fileResults"));
    assertEquals("", result.getText());
    File file = File.createTempFile("test", "txt");
    file.deleteOnExit();
    uploadElement.sendKeys(file.getAbsolutePath());
    // Shift focus to something else because send key doesn't make the focus leave
    d.findElement(By.id("id-name1")).click();
    assertEquals("changed", result.getText());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 95 with WebDriver

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

the class FileUploadTest method checkFileUploadCompletes.

@Test
public void checkFileUploadCompletes() throws IOException {
    WebDriver d = getDriver();
    // 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
    d.get(server.getBaseUrl() + "/common/upload.html");
    d.findElement(By.id("upload")).sendKeys(testFile.getAbsolutePath());
    d.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(d, 10);
    wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("upload_label")));
    d.switchTo().frame("upload_target");
    wait = new WebDriverWait(d, 5);
    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//body"), LOREM_IPSUM_TEXT));
    // Navigate after file upload to verify callbacks are properly released.
    d.get("http://www.google.com/");
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HttpRequestCallback(ghostdriver.server.HttpRequestCallback) HttpServletResponse(javax.servlet.http.HttpServletResponse) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) List(java.util.List) FileUploadException(org.apache.commons.fileupload.FileUploadException) 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