Search in sources :

Example 11 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class HistoryTest method historyCache.

/**
 * Tests going in history {@link History#back()} with {@code POST} request.
 *
 * @throws Exception if an error occurs
 */
@Test
@Alerts("49")
public // limit varies for IE
void historyCache() throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    final int testDeep = 70;
    for (int i = 0; i < testDeep; i++) {
        servlets.put("/post" + i, Post1Servlet.class);
    }
    startWebServer("./", new String[0], servlets);
    final WebDriver driver = getWebDriver();
    int count = Post1Servlet.Count_;
    for (int i = 0; i < testDeep; i++) {
        driver.get(URL_FIRST + "post" + i);
        assertTrue(driver.getPageSource(), driver.getPageSource().contains("Call: " + (i + count)));
    }
    count = Post1Servlet.Count_;
    for (int i = 0; i < testDeep - 1; i++) {
        driver.navigate().back();
        if (!driver.getPageSource().contains("Call: " + (count - i - 2))) {
            assertEquals(Integer.parseInt(getExpectedAlerts()[0]), i);
            return;
        }
        if (count != Post1Servlet.Count_) {
            Assert.fail("Server called for " + i);
            break;
        }
    }
    assertEquals(getExpectedAlerts()[0], "done");
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HashMap(java.util.HashMap) HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 12 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class HttpWebConnection3Test method acceptEncoding.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = "gzip, deflate", CHROME = "gzip, deflate, br", EDGE = "gzip, deflate, br")
public void acceptEncoding() throws Exception {
    final String response = "HTTP/1.1 200 OK\r\n" + "Content-Length: 2\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "Hi";
    shutDownAll();
    try (PrimitiveWebServer primitiveWebServer = new PrimitiveWebServer(null, response, null)) {
        final WebDriver driver = getWebDriver();
        driver.get("http://localhost:" + primitiveWebServer.getPort());
        final String request = primitiveWebServer.getRequests().get(0);
        final String[] headers = request.split("\\r\\n");
        for (int i = 0; i < headers.length; i++) {
            final String header = headers[i];
            if (StringUtils.startsWithIgnoreCase(header, HttpHeader.ACCEPT_ENCODING_LC)) {
                final String value = header.substring(header.indexOf(':') + 1);
                assertEquals(getExpectedAlerts()[0], value.trim());
                return;
            }
        }
        fail("No accept-encoding header found.");
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 13 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class HttpWebConnection3Test method locationUTF.

/**
 * Test for bug #1898.
 *
 * @throws Exception if an error occurs
 */
@Test
@Alerts("§§URL§§?????")
public // seems to work only when running alone
void locationUTF() throws Exception {
    final String url = "http://localhost:" + PORT_PRIMITIVE_SERVER + "/";
    final String response = "HTTP/1.1 302 Found\r\n" + "Content-Length: 0\r\n" + "Location: " + url + "\u0623\u0647\u0644\u0627\u064b" + "\r\n" + "\r\n";
    final String response2 = "HTTP/1.1 200 OK\r\n" + "Content-Length: 2\r\n" + "Content-Type: text/html\r\n" + "\r\n" + "Hi";
    expandExpectedAlertsVariables(new URL(url));
    shutDownAll();
    try (PrimitiveWebServer primitiveWebServer = new PrimitiveWebServer(null, response, response2)) {
        final WebDriver driver = getWebDriver();
        driver.get(url);
        assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());
        assertTrue(driver.getPageSource().contains("Hi"));
        assertEquals(2, primitiveWebServer.getRequests().size());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) URL(java.net.URL) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 14 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class CookieManagerTest method setCookieExpires_twoDigits2.

/**
 * Two digits years should be interpreted as 20xx if before 1970 and as 19xx otherwise.
 * Same as the test before, only different formating was used.
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = "cookie1=1; cookie2=2; cookie3=3", IE = "cookie1=1; cookie2=2; cookie3=3; cookie4=4; cookie5=5; cookie6=6")
public void setCookieExpires_twoDigits2() throws Exception {
    final List<NameValuePair> responseHeader1 = new ArrayList<>();
    responseHeader1.add(new NameValuePair("Set-Cookie", "cookie1=1;expires=Sun,01 Dec 68 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "cookie2=2;expires=Thu,01 Dec 69 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "cookie3=3;expires=Mon,31 Dec 69 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "cookie4=4;expires=Thu,01 Jan 70 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "cookie5=5;expires=Tue,01 Dec 70 16:00:00 GMT"));
    responseHeader1.add(new NameValuePair("Set-Cookie", "cookie6=6;expires=Wed,01 Dec 71 16:00:00 GMT"));
    getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader1);
    loadPageWithAlerts2(URL_FIRST);
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) ArrayList(java.util.ArrayList) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 15 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class CookieManagerTest method emptyCookieName.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("value1")
public void emptyCookieName() throws Exception {
    final List<NameValuePair> responseHeader = new ArrayList<>();
    responseHeader.add(new NameValuePair("Set-Cookie", "=value1"));
    getMockWebConnection().setDefaultResponse(HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader);
    loadPageWithAlerts2(URL_FIRST);
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) ArrayList(java.util.ArrayList) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Aggregations

Alerts (com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)1266 Test (org.junit.Test)1261 WebDriver (org.openqa.selenium.WebDriver)894 HtmlPageTest (com.gargoylesoftware.htmlunit.html.HtmlPageTest)398 URL (java.net.URL)238 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)206 BuggyWebDriver (com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)159 WebElement (org.openqa.selenium.WebElement)146 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)128 MSXMLTestHelper.callLoadXMLDOMDocumentFromString (com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestHelper.callLoadXMLDOMDocumentFromString)101 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)97 ArrayList (java.util.ArrayList)90 HtmlUnitNYI (com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)72 NotYetImplemented (com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented)54 MockWebConnection (com.gargoylesoftware.htmlunit.MockWebConnection)48 XMLDocumentTest.callLoadXMLDocumentFromString (com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocumentTest.callLoadXMLDocumentFromString)47 XMLDocumentTest.callSerializeXMLDocumentToString (com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocumentTest.callSerializeXMLDocumentToString)44 File (java.io.File)30 WebClient (com.gargoylesoftware.htmlunit.WebClient)29 InputStream (java.io.InputStream)29