Search in sources :

Example 11 with BuggyWebDriver

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

the class HtmlMapTest method mapClick.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("§§URL§§a.html")
@BuggyWebDriver(FF = "Element <area id=\"tester\" href=\"a.html\"> could not be scrolled into view", FF_ESR = "Element <area id=\"tester\" href=\"a.html\"> could not be scrolled into view", IE = "§§URL§§")
public void mapClick() throws Exception {
    final URL urlImage = new URL(URL_FIRST, "img.jpg");
    try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/4x7.jpg")) {
        final byte[] directBytes = IOUtils.toByteArray(is);
        final List<NameValuePair> emptyList = Collections.emptyList();
        getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", emptyList);
    }
    final String html = "<html>\n" + "<head></head>" + "<body>\n" + "  <img id='myImg' src='" + urlImage + "' usemap='#map1'>\n" + "  <map name='map1'>\n" + "    <area id='tester' href='a.html' shape='rect' coords='0,0,4,4'>\n" + "  </map>\n" + "</body></html>";
    final String secondContent = "<html><head><title>Second</title></head><body></body></html>";
    final MockWebConnection webConnection = getMockWebConnection();
    webConnection.setDefaultResponse(secondContent);
    final WebDriver driver = loadPage2(html);
    expandExpectedAlertsVariables(URL_FIRST);
    try {
        driver.findElement(By.id("tester")).click();
        assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());
        assertSame("method", HttpMethod.GET, webConnection.getLastMethod());
    } catch (final Exception e) {
        assertEquals(getExpectedAlerts()[0], e.getMessage().substring(0, getExpectedAlerts()[0].length()));
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) InputStream(java.io.InputStream) MockWebConnection(com.gargoylesoftware.htmlunit.MockWebConnection) URL(java.net.URL) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 12 with BuggyWebDriver

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

the class ConsoleTest method simpleString.

/**
 * @throws Exception if the test fails
 */
@Test
@BuggyWebDriver
public void simpleString() throws Exception {
    final String html = "<html>\n" + "<body>\n" + "<script>\n" + "  for (i = 0; i < 4; i++) {\n" + "    console.log('test log ' + i);\n" + "  }\n" + "</script>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    final Logs logs = driver.manage().logs();
    final LogEntries logEntries = logs.get(LogType.BROWSER);
    final List<LogEntry> logEntryList = logEntries.getAll();
    final int count = logEntryList.size();
    assertTrue(count > 0);
    long timestamp = 0;
    for (int i = 0; i < 4; i++) {
        final LogEntry logEntry = logEntryList.get(i);
        assertTrue(logEntry.getMessage(), logEntry.getMessage().contains("test log " + i));
        assertTrue(logEntry.getTimestamp() >= timestamp);
        timestamp = logEntry.getTimestamp();
    }
}
Also used : BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebDriver(org.openqa.selenium.WebDriver) LogEntries(org.openqa.selenium.logging.LogEntries) Logs(org.openqa.selenium.logging.Logs) LogEntry(org.openqa.selenium.logging.LogEntry) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)

Example 13 with BuggyWebDriver

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

the class ConsoleTest method assertOnly.

/**
 * @throws Exception if the test fails
 */
@Test
@BuggyWebDriver
public void assertOnly() throws Exception {
    final String html = "<html>\n" + "<body>\n" + "<script>\n" + "  number = 1;\n" + "  console.assert(number % 2 === 0);\n" + "</script>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    final Logs logs = driver.manage().logs();
    final LogEntries logEntries = logs.get(LogType.BROWSER);
    final List<LogEntry> logEntryList = logEntries.getAll();
    assertEquals(1, logEntryList.size());
    final LogEntry logEntry = logEntryList.get(0);
    assertTrue(logEntry.getMessage(), logEntry.getMessage().contains("Assertion failed"));
}
Also used : BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebDriver(org.openqa.selenium.WebDriver) LogEntries(org.openqa.selenium.logging.LogEntries) Logs(org.openqa.selenium.logging.Logs) LogEntry(org.openqa.selenium.logging.LogEntry) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)

Example 14 with BuggyWebDriver

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

the class ConsoleTest method trace.

/**
 * @throws Exception if the test fails
 */
@Test
@BuggyWebDriver
public void trace() throws Exception {
    final String html = "<html>\n" + "<body>\n" + "<script>\n" + "  function foo() {\n" + "    function bar() {\n" + "      console.trace();\n" + "    }\n" + "    bar();\n" + "  }\n" + "  foo();\n" + "</script>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    final Logs logs = driver.manage().logs();
    final LogEntries logEntries = logs.get(LogType.BROWSER);
    final List<LogEntry> logEntryList = logEntries.getAll();
    assertEquals(1, logEntryList.size());
    final LogEntry logEntry = logEntryList.get(0);
    final String logMsg = logEntry.getMessage();
    System.out.println(logMsg);
    assertTrue(logMsg, logMsg.matches("bar\\(\\)@script in http.*:6\\n" + "foo\\(\\)@script in http.*:8\\n" + "@script in http.*:10\\n" + ".*"));
}
Also used : BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebDriver(org.openqa.selenium.WebDriver) LogEntries(org.openqa.selenium.logging.LogEntries) Logs(org.openqa.selenium.logging.Logs) LogEntry(org.openqa.selenium.logging.LogEntry) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)

Example 15 with BuggyWebDriver

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

the class ConsoleTest method assertObject.

/**
 * @throws Exception if the test fails
 */
@Test
@BuggyWebDriver
public void assertObject() throws Exception {
    final String html = "<html>\n" + "<body>\n" + "<script>\n" + "  number = 1;\n" + "  console.assert(number % 2 === 0, {number: number, errorMsg: 'the # is not even'});\n" + "</script>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    final Logs logs = driver.manage().logs();
    final LogEntries logEntries = logs.get(LogType.BROWSER);
    final List<LogEntry> logEntryList = logEntries.getAll();
    assertEquals(1, logEntryList.size());
    final LogEntry logEntry = logEntryList.get(0);
    assertTrue(logEntry.getMessage(), logEntry.getMessage().contains("Assertion failed: ({number: 1.0, errorMsg: \"the # is not even\"})"));
}
Also used : BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebDriver(org.openqa.selenium.WebDriver) LogEntries(org.openqa.selenium.logging.LogEntries) Logs(org.openqa.selenium.logging.Logs) LogEntry(org.openqa.selenium.logging.LogEntry) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)

Aggregations

BuggyWebDriver (com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)43 Test (org.junit.Test)42 WebDriver (org.openqa.selenium.WebDriver)41 Alerts (com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)35 WebElement (org.openqa.selenium.WebElement)15 HtmlPageTest (com.gargoylesoftware.htmlunit.html.HtmlPageTest)11 Actions (org.openqa.selenium.interactions.Actions)8 LogEntries (org.openqa.selenium.logging.LogEntries)8 LogEntry (org.openqa.selenium.logging.LogEntry)8 Logs (org.openqa.selenium.logging.Logs)8 URL (java.net.URL)7 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)6 LinkedList (java.util.LinkedList)5 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)5 NotYetImplemented (com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented)4 InputStream (java.io.InputStream)4 Page (com.gargoylesoftware.htmlunit.Page)3 Action (org.openqa.selenium.interactions.Action)3 HtmlUnitNYI (com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)2 MockWebConnection (com.gargoylesoftware.htmlunit.MockWebConnection)1