Example usage for org.openqa.selenium WebDriver manage

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

Introduction

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

Prototype

Options manage();

Source Link

Document

Gets the Option interface

Usage

From source file:com.gargoylesoftware.htmlunit.CookieManager4Test.java

License:Apache License

/**
 * @throws Exception if the test fails//from w ww .j  a va  2  s .  com
 */
@Test
public void storedDomainFromJs1() throws Exception {
    final String html = "<html>\n" + "<head>\n" + "</head>\n" + "<body>\n" + "<p>Cookie Domain Test</p>\n"
            + "<script>\n" + "  document.cookie='c1=1; Domain=." + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c2=2; Domain=" + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c3=3; Domain=.host1." + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c4=4; Domain=host1." + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c5=5; Domain=." + DOMAIN + ":" + PORT + "; Path=/';\n"
            + "  document.cookie='c6=6; Domain=" + DOMAIN + ":" + PORT + "; Path=/';\n"
            + "  document.cookie='c7=7; Domain=.host1." + DOMAIN + ":" + PORT + "; Path=/';\n"
            + "  document.cookie='c8=8; Domain=host1." + DOMAIN + ":" + PORT + "; Path=/';\n"

            + "  document.cookie='c9=9; Domain=.org; Path=/';\n"
            + "  document.cookie='c10=10; Domain=org; Path=/';\n"
            + "  document.cookie='c11=11; Domain=.htmlunit; Path=/';\n"
            + "  document.cookie='c12=12; Domain=htmlunit; Path=/';\n" + "</script>\n" + "</body>\n"
            + "</html>";

    final WebDriver driver = loadPageWithAlerts2(html, new URL(URL_HOST1));

    assertEquals(4, driver.manage().getCookies().size());
    assertEquals("c1=1; path=/; domain=.htmlunit.org", driver.manage().getCookieNamed("c1").toString());
    assertEquals("c2=2; path=/; domain=.htmlunit.org", driver.manage().getCookieNamed("c2").toString());
    assertEquals("c3=3; path=/; domain=.host1.htmlunit.org", driver.manage().getCookieNamed("c3").toString());
    assertEquals("c4=4; path=/; domain=.host1.htmlunit.org", driver.manage().getCookieNamed("c4").toString());
}

From source file:com.gargoylesoftware.htmlunit.CookieManager4Test.java

License:Apache License

/**
 * @throws Exception if the test fails//from   w w w.  j  a v  a 2s .c  o  m
 */
@Test
public void storedDomainFromJs2() throws Exception {
    final String html = "<html>\n" + "<head>\n" + "</head>\n" + "<body>\n" + "<p>Cookie Domain Test</p>\n"
            + "<script>\n" + "  document.cookie='c1=1; Domain=." + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c2=2; Domain=" + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c3=3; Domain=.host1." + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c4=4; Domain=host1." + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c5=5; Domain=." + DOMAIN + ":" + PORT + "; Path=/';\n"
            + "  document.cookie='c6=6; Domain=" + DOMAIN + ":" + PORT + "; Path=/';\n"
            + "  document.cookie='c7=7; Domain=.host1." + DOMAIN + ":" + PORT + "; Path=/';\n"
            + "  document.cookie='c8=8; Domain=host1." + DOMAIN + ":" + PORT + "; Path=/';\n"

            + "  document.cookie='c9=9; Domain=.org; Path=/';\n"
            + "  document.cookie='c10=10; Domain=org; Path=/';\n"
            + "  document.cookie='c11=11; Domain=.htmlunit; Path=/';\n"
            + "  document.cookie='c12=12; Domain=htmlunit; Path=/';\n" + "</script>\n" + "</body>\n"
            + "</html>";

    final WebDriver driver = loadPageWithAlerts2(html, new URL(URL_HOST2));

    assertEquals(2, driver.manage().getCookies().size());
    assertEquals("c1=1; path=/; domain=.htmlunit.org", driver.manage().getCookieNamed("c1").toString());
    assertEquals("c2=2; path=/; domain=.htmlunit.org", driver.manage().getCookieNamed("c2").toString());
}

From source file:com.gargoylesoftware.htmlunit.CookieManager4Test.java

License:Apache License

/**
 * @throws Exception if the test fails//from   w w  w  . j a va  2s  .  c  o m
 */
@Test
public void storedDomainFromJs3() throws Exception {
    final String html = "<html>\n" + "<head>\n" + "</head>\n" + "<body>\n" + "<p>Cookie Domain Test</p>\n"
            + "<script>\n" + "  document.cookie='c1=1; Domain=." + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c2=2; Domain=" + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c3=3; Domain=.host1." + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c4=4; Domain=host1." + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c5=5; Domain=." + DOMAIN + ":" + PORT + "; Path=/';\n"
            + "  document.cookie='c6=6; Domain=" + DOMAIN + ":" + PORT + "; Path=/';\n"
            + "  document.cookie='c7=7; Domain=.host1." + DOMAIN + ":" + PORT + "; Path=/';\n"
            + "  document.cookie='c8=8; Domain=host1." + DOMAIN + ":" + PORT + "; Path=/';\n"

            + "  document.cookie='c9=9; Domain=.org; Path=/';\n"
            + "  document.cookie='c10=10; Domain=org; Path=/';\n"
            + "  document.cookie='c11=11; Domain=.htmlunit; Path=/';\n"
            + "  document.cookie='c12=12; Domain=htmlunit; Path=/';\n" + "</script>\n" + "</body>\n"
            + "</html>";

    final WebDriver driver = loadPageWithAlerts2(html, new URL(URL_HOST3));

    assertEquals(2, driver.manage().getCookies().size());
    assertEquals("c1=1; path=/; domain=.htmlunit.org", driver.manage().getCookieNamed("c1").toString());
    assertEquals("c2=2; path=/; domain=.htmlunit.org", driver.manage().getCookieNamed("c2").toString());
}

From source file:com.gargoylesoftware.htmlunit.CookieManager4Test.java

License:Apache License

/**
 * @throws Exception if the test fails/*from  ww  w .  j a  v a  2s .c o  m*/
 */
@Test
@Alerts(DEFAULT = { "2", "c12=12; path=/; domain=htmlunit", "c11=11; path=/; domain=htmlunit" }, CHROME = { "1",
        "c12=12; path=/; domain=htmlunit" })
public void storedDomainFromJs4() throws Exception {
    final String html = "<html>\n" + "<head>\n" + "</head>\n" + "<body>\n" + "<p>Cookie Domain Test</p>\n"
            + "<script>\n" + "  document.cookie='c1=1; Domain=." + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c2=2; Domain=" + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c3=3; Domain=.host1." + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c4=4; Domain=host1." + DOMAIN + "; Path=/';\n"
            + "  document.cookie='c5=5; Domain=." + DOMAIN + ":" + PORT + "; Path=/';\n"
            + "  document.cookie='c6=6; Domain=" + DOMAIN + ":" + PORT + "; Path=/';\n"
            + "  document.cookie='c7=7; Domain=.host1." + DOMAIN + ":" + PORT + "; Path=/';\n"
            + "  document.cookie='c8=8; Domain=host1." + DOMAIN + ":" + PORT + "; Path=/';\n"

            + "  document.cookie='c9=9; Domain=.org; Path=/';\n"
            + "  document.cookie='c10=10; Domain=org; Path=/';\n"
            + "  document.cookie='c11=11; Domain=.htmlunit; Path=/';\n"
            + "  document.cookie='c12=12; Domain=htmlunit; Path=/';\n" + "</script>\n" + "</body>\n"
            + "</html>";

    final WebDriver driver = loadPage2(html, new URL(URL_HOST4));

    final String[] expected = getExpectedAlerts();
    assertEquals(Integer.parseInt(expected[0]), driver.manage().getCookies().size());
    assertEquals(expected[1], driver.manage().getCookieNamed("c12").toString());
    if (Integer.parseInt(expected[0]) > 1) {
        assertEquals(expected[2], driver.manage().getCookieNamed("c11").toString());
    }
}

From source file:com.gargoylesoftware.htmlunit.CookieManager4Test.java

License:Apache License

/**
 * @throws Exception if the test fails/* www .j  a v a2 s .c om*/
 */
@Test
public void domainDuplicateLeadingDotSend() throws Exception {
    final String html = "<html><body>\n" + "<a href='next.html'>next page</a>\n" + "</body></html>";

    final List<NameValuePair> responseHeader = new ArrayList<>();
    responseHeader.add(new NameValuePair("Set-Cookie", "c1=1; Domain=host1." + DOMAIN + "; Path=/"));
    responseHeader.add(new NameValuePair("Set-Cookie", "c2=2; Domain=.host1." + DOMAIN + "; Path=/"));

    getMockWebConnection().setDefaultResponse(html, 200, "Ok", "text/html", responseHeader);

    final WebDriver webDriver = getWebDriver();
    webDriver.manage().deleteAllCookies();

    loadPageWithAlerts2(new URL(URL_HOST1));
    WebRequest lastRequest = getMockWebConnection().getLastWebRequest();
    assertNull(lastRequest.getAdditionalHeaders().get("Cookie"));

    webDriver.findElement(By.linkText("next page")).click();
    lastRequest = getMockWebConnection().getLastWebRequest();
    assertEquals("c1=1; c2=2", lastRequest.getAdditionalHeaders().get("Cookie"));
}

From source file:com.gargoylesoftware.htmlunit.CookieManager4Test.java

License:Apache License

/**
 * @throws Exception if the test fails/*w w w. j av a2s .c o m*/
 */
@Test
public void domainDuplicateLeadingDotRedirect() throws Exception {
    final String html = "<html><body>\n" + "<a href='next.html'>next page</a>\n" + "</body></html>";

    final List<NameValuePair> responseHeader = new ArrayList<>();
    responseHeader.add(new NameValuePair("Set-Cookie",
            "c1=1; Domain=host1." + DOMAIN + "; path=/; expires=Fri, 04-Feb-2022 09:00:32 GMT"));
    responseHeader.add(new NameValuePair("Set-Cookie",
            "c2=2; Domain=.host1." + DOMAIN + "; path=/; expires=Fri, 04-Feb-2022 09:00:32 GMT"));

    getMockWebConnection().setDefaultResponse(html, 200, "Ok", "text/html", responseHeader);

    responseHeader.add(new NameValuePair("Location", URL_HOST1 + "next.html"));
    getMockWebConnection().setResponse(new URL(URL_HOST1), "redirect", 301, "Ok", "text/html", responseHeader);

    final WebDriver webDriver = getWebDriver();
    webDriver.manage().deleteAllCookies();

    final int startCount = getMockWebConnection().getRequestCount();
    loadPageWithAlerts2(new URL(URL_HOST1));
    assertEquals(2, getMockWebConnection().getRequestCount() - startCount);
    final WebRequest lastRequest = getMockWebConnection().getLastWebRequest();
    assertEquals("c1=1; c2=2", lastRequest.getAdditionalHeaders().get("Cookie"));
}

From source file:com.gargoylesoftware.htmlunit.CookieManagerTest.java

License:Apache License

/**
 * @throws Exception if the test fails/*from www  . jav a2  s. c  o  m*/
 */
@Test
// TODO [IE]SINGLE-VS-BULK test runs when executed as single but breaks as bulk
public void orderCookiesByPath_fromJs() throws Exception {
    final String html = "<html><body><script>\n" + "document.cookie = 'exampleCookie=rootPath;path=/';\n"
            + "document.cookie = 'exampleCookie=currentPath;path=/testpages/';\n" + "</script>\n"
            + "<a href='/testpages/next.html'>next page</a>\n" + "</body></html>";

    getMockWebConnection().setDefaultResponse("");

    final WebDriver webDriver = getWebDriver();
    webDriver.manage().deleteAllCookies();

    loadPage2(html);
    webDriver.findElement(By.linkText("next page")).click();

    final WebRequest lastRequest = getMockWebConnection().getLastWebRequest();
    assertEquals("exampleCookie=currentPath; exampleCookie=rootPath",
            lastRequest.getAdditionalHeaders().get("Cookie"));
}

From source file:com.gargoylesoftware.htmlunit.CookieManagerTest.java

License:Apache License

/**
 * @throws Exception if the test fails// w  ww  .  j  a  va2s  .  c o m
 */
@Test
@Alerts("dog=dalmation")
public void trailing_slash() throws Exception {
    final WebDriver driver = getWebDriver();
    loadPage2(HTML_ALERT_COOKIE, URL_SECOND);
    driver.manage().addCookie(new org.openqa.selenium.Cookie("dog", "dalmation", "/second/"));
    loadPageWithAlerts2(HTML_ALERT_COOKIE, URL_SECOND);
}

From source file:com.gargoylesoftware.htmlunit.libraries.MochiKitTest.java

License:Apache License

private void doTest(final String testName) throws Exception {
    final String url = URL_FIRST + "tests/test_MochiKit-" + testName + ".html";
    assertNotNull(url);/*w w  w.  ja va2 s.  c o m*/

    final WebDriver driver = getWebDriver();
    driver.get(url);

    // make single test results visible
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    driver.findElement(By.linkText("Toggle passed tests")).click();
    driver.findElement(By.linkText("Toggle failed tests")).click();
    driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);

    String expected = loadExpectation(testName);
    expected = expected.trim();
    expected = StringUtils.replace(expected, "\r\n", "\n");
    final WebElement div = driver.findElement(By.xpath("//div[@class = 'tests_report']"));

    assertNotNull(div);
    String actual = div.getText().trim();
    actual = StringUtils.replace(actual, "\n\n", "\n");
    assertEquals(expected.trim(), actual);
}

From source file:com.gargoylesoftware.htmlunit.libraries.MooTools121Test.java

License:Apache License

/**
 * @throws Exception if an error occurs/*from   w w w  . ja  va  2 s.c  o m*/
 */
@Alerts(CHROME = { "364", "1", "0",
        "should return the function bound to an object with multiple arguments" }, IE = { "364", "2", "0",
                "should return the function bound to an object with multiple arguments",
                "should return a CSS string representing the Element's styles" }, FF = { "364", "2", "0",
                        "should return true if the string constains the string and separator otherwise false",
                        "should return the function bound to an object with multiple arguments" })
@Test
@NotYetImplemented(IE)
public void mooTools() throws Exception {
    final WebDriver driver = getWebDriver();
    driver.get(URL_FIRST + "Specs/index.html");

    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    driver.findElement(By.xpath("id('progress')[text() = '100']"));
    // usually this need 40s but sometimes our build machine is slower
    // this is not an performance test, we only like to ensure that all
    // functionality is running

    final List<WebElement> failed = driver.findElements(By.xpath("//li[@class = 'exception']/h4"));
    final List<String> failures = new ArrayList<>();
    for (final WebElement elt : failed) {
        failures.add(elt.getText());
    }

    // final File tmpFile = File.createTempFile("htmlunit", "mootools.html");
    // System.out.println(tmpFile.getAbsolutePath());
    // FileUtils.writeStringToFile(tmpFile, driver.getPageSource());

    assertEquals(Arrays.copyOfRange(getExpectedAlerts(), 3, getExpectedAlerts().length), failures);

    assertEquals(getExpectedAlerts()[0], driver.findElement(By.id("total_examples")).getText());
    assertEquals(getExpectedAlerts()[1], driver.findElement(By.id("total_failures")).getText());
    assertEquals(getExpectedAlerts()[2], driver.findElement(By.id("total_errors")).getText());
}