Example usage for org.openqa.selenium WebDriver get

List of usage examples for org.openqa.selenium WebDriver get

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver get.

Prototype

void get(String url);

Source Link

Document

Load a new web page in the current browser window.

Usage

From source file:com.gargoylesoftware.htmlunit.html.HtmlArea2Test.java

License:Apache License

/**
 * @throws Exception if the test fails/*from   w  w  w. j a  va 2s . c o m*/
 */
@Test
public void referer() throws Exception {
    final WebDriver driver = createWebClient("");

    driver.get(URL_FIRST.toExternalForm());
    driver.findElement(By.id("third")).click();

    final Map<String, String> lastAdditionalHeaders = getMockWebConnection().getLastAdditionalHeaders();
    assertEquals(URL_FIRST.toString(), lastAdditionalHeaders.get("Referer"));
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlFileInput2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs/*  ww w  .  j a v  a 2 s.c  om*/
 */
@Test
@Alerts(DEFAULT = { "CONTENT_TYPE:application/octet-stream", "charset" }, IE = { "CONTENT_TYPE:text/plain",
        "charset" })
@NotYetImplemented(IE)
public void contentType() throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    servlets.put("/upload1", Upload1Servlet.class);
    servlets.put("/upload2", ContentTypeUpload2Servlet.class);
    startWebServer("./", new String[0], servlets);

    final WebDriver driver = getWebDriver();
    driver.get("http://localhost:" + PORT + "/upload1");
    String path = getClass().getClassLoader().getResource("realm.properties").toExternalForm();
    if (driver instanceof InternetExplorerDriver || driver instanceof ChromeDriver) {
        path = path.substring(path.indexOf('/') + 1).replace('/', '\\');
    }
    driver.findElement(By.name("myInput")).sendKeys(path);
    driver.findElement(By.id("mySubmit")).click();

    final String pageSource = driver.getPageSource();
    assertTrue(pageSource, pageSource.contains(getExpectedAlerts()[0]));
    assertFalse(pageSource, pageSource.contains(getExpectedAlerts()[1]));
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlFileInput2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs/*w ww . j a v  a2  s . co  m*/
 */
@Test
public void contentTypeHeader() throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    servlets.put("/upload1", Upload1Servlet.class);
    servlets.put("/upload2", ContentTypeHeaderUpload2Servlet.class);
    startWebServer("./", new String[0], servlets);

    final WebDriver driver = getWebDriver();
    driver.get("http://localhost:" + PORT + "/upload1");
    String path = getClass().getClassLoader().getResource("realm.properties").toExternalForm();
    if (driver instanceof InternetExplorerDriver || driver instanceof ChromeDriver) {
        path = path.substring(path.indexOf('/') + 1).replace('/', '\\');
    }
    driver.findElement(By.name("myInput")).sendKeys(path);
    driver.findElement(By.id("mySubmit")).click();
    final String source = driver.getPageSource();
    assertTrue(source.contains("CONTENT_TYPE:"));
    assertFalse(source.contains("charset"));
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlFileInput2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs/*from  www . jav  a 2s.  c  om*/
 */
@Test
@Alerts("Content-Disposition: form-data; name=\"myInput\"; filename=\"\"")
public void empty() throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    servlets.put("/upload1", Upload1Servlet.class);
    servlets.put("/upload2", PrintRequestServlet.class);
    startWebServer("./", new String[0], servlets);

    final WebDriver driver = getWebDriver();
    driver.get("http://localhost:" + PORT + "/upload1");
    driver.findElement(By.id("mySubmit")).click();

    String pageSource = driver.getPageSource();
    // hack for selenium
    int count = 0;
    while (count < 100 && StringUtils.isEmpty(pageSource)) {
        pageSource = driver.getPageSource();
        count++;
    }

    final Matcher matcher = Pattern.compile(getExpectedAlerts()[0]).matcher(pageSource);
    assertTrue(pageSource, matcher.find());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlFileInput2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs/*from w  w  w .  j  av  a2s.  c o  m*/
 */
@Test
@Alerts(DEFAULT = "Content-Disposition: form-data; name=\"myInput\"; filename=\"realm.properties\"", IE = "Content-Disposition: form-data; name=\"myInput\";"
        + " filename=\".*test-classes[\\\\/]realm\\.properties\"")
public void realFile() throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    servlets.put("/upload1", Upload1Servlet.class);
    servlets.put("/upload2", PrintRequestServlet.class);
    startWebServer("./", new String[0], servlets);

    final WebDriver driver = getWebDriver();
    driver.get("http://localhost:" + PORT + "/upload1");
    String path = getClass().getClassLoader().getResource("realm.properties").toExternalForm();
    if (driver instanceof InternetExplorerDriver || driver instanceof ChromeDriver) {
        path = path.substring(path.indexOf('/') + 1).replace('/', '\\');
    }
    driver.findElement(By.name("myInput")).sendKeys(path);
    driver.findElement(By.id("mySubmit")).click();

    String pageSource = driver.getPageSource();
    // hack for selenium
    int count = 0;
    while (count < 100 && StringUtils.isEmpty(pageSource)) {
        pageSource = driver.getPageSource();
        count++;
    }

    final Matcher matcher = Pattern.compile(getExpectedAlerts()[0]).matcher(pageSource);
    assertTrue(pageSource, matcher.find());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlFileInput2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs//from w  ww.  j a  v  a 2  s.  c o  m
 */
@Test
public void chunked() throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    servlets.put("/upload1", Upload1Servlet.class);
    servlets.put("/upload2", ChunkedUpload2Servlet.class);
    startWebServer("./", new String[0], servlets);

    final WebDriver driver = getWebDriver();
    driver.get("http://localhost:" + PORT + "/upload1");
    driver.findElement(By.id("mySubmit")).click();
    assertFalse(driver.getPageSource().contains("chunked"));
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlFileInputTest.java

License:Apache License

private void contentType(final String extension) throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    servlets.put("/upload1", Upload1Servlet.class);
    servlets.put("/upload2", ContentTypeUpload2Servlet.class);
    startWebServer("./", new String[0], servlets);

    final WebDriver driver = getWebDriver();
    driver.get(URL_FIRST + "upload1");

    final File tmpFile = File.createTempFile("htmlunit-test", "." + extension);
    try {/*w  w  w . j  av a  2 s .  c  o  m*/
        String path = tmpFile.getAbsolutePath();
        if (driver instanceof InternetExplorerDriver || driver instanceof ChromeDriver) {
            path = path.substring(path.indexOf('/') + 1).replace('/', '\\');
        }
        driver.findElement(By.name("myInput")).sendKeys(path);
        driver.findElement(By.id("mySubmit")).click();
    } finally {
        tmpFile.delete();
    }

    final String pageSource = driver.getPageSource();
    assertTrue(pageSource, pageSource.contains(getExpectedAlerts()[0]));
    assertFalse(pageSource, pageSource.contains(getExpectedAlerts()[1]));
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlFileInputTest.java

License:Apache License

/**
 * @throws Exception if an error occurs//from w w  w.  j  a  v a2  s .co  m
 */
@Test
public void contentTypeHeader() throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    servlets.put("/upload1", Upload1Servlet.class);
    servlets.put("/upload2", ContentTypeHeaderUpload2Servlet.class);
    startWebServer("./", new String[0], servlets);

    final WebDriver driver = getWebDriver();
    driver.get(URL_FIRST + "upload1");
    String path = getClass().getClassLoader().getResource("realm.properties").toExternalForm();
    if (driver instanceof InternetExplorerDriver || driver instanceof ChromeDriver) {
        path = path.substring(path.indexOf('/') + 1).replace('/', '\\');
    }
    driver.findElement(By.name("myInput")).sendKeys(path);
    driver.findElement(By.id("mySubmit")).click();
    final String source = driver.getPageSource();
    assertTrue(source.contains("CONTENT_TYPE:"));
    assertFalse(source.contains("charset"));
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlFileInputTest.java

License:Apache License

/**
 * @throws Exception if an error occurs// w  w  w .  ja  v  a2  s  .com
 */
@Test
@Alerts("Content-Disposition: form-data; name=\"myInput\"; filename=\"\"")
public void empty() throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    servlets.put("/upload1", Upload1Servlet.class);
    servlets.put("/upload2", PrintRequestServlet.class);
    startWebServer("./", new String[0], servlets);

    final WebDriver driver = getWebDriver();
    driver.get(URL_FIRST + "upload1");
    driver.findElement(By.id("mySubmit")).click();

    String pageSource = driver.getPageSource();
    // hack for selenium
    int count = 0;
    while (count < 100 && StringUtils.isEmpty(pageSource)) {
        pageSource = driver.getPageSource();
        count++;
    }

    final Matcher matcher = Pattern.compile(getExpectedAlerts()[0]).matcher(pageSource);
    assertTrue(pageSource, matcher.find());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlFileInputTest.java

License:Apache License

/**
 * @throws Exception if an error occurs//from w w w .  j  a  v a 2  s  .c  o m
 */
@Test
@Alerts(DEFAULT = "Content-Disposition: form-data; name=\"myInput\"; filename=\"realm.properties\"", IE = "Content-Disposition: form-data; name=\"myInput\";"
        + " filename=\".*test-classes[\\\\/]realm\\.properties\"")
public void realFile() throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    servlets.put("/upload1", Upload1Servlet.class);
    servlets.put("/upload2", PrintRequestServlet.class);
    startWebServer("./", new String[0], servlets);

    final WebDriver driver = getWebDriver();
    driver.get(URL_FIRST + "upload1");
    String path = getClass().getClassLoader().getResource("realm.properties").toExternalForm();
    if (driver instanceof InternetExplorerDriver || driver instanceof ChromeDriver) {
        path = path.substring(path.indexOf('/') + 1).replace('/', '\\');
    }
    driver.findElement(By.name("myInput")).sendKeys(path);
    driver.findElement(By.id("mySubmit")).click();

    String pageSource = driver.getPageSource();
    // hack for selenium
    int count = 0;
    while (count < 100 && StringUtils.isEmpty(pageSource)) {
        pageSource = driver.getPageSource();
        count++;
    }

    final Matcher matcher = Pattern.compile(getExpectedAlerts()[0]).matcher(pageSource);
    assertTrue(pageSource, matcher.find());
}