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()));
}
}
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();
}
}
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"));
}
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" + ".*"));
}
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\"})"));
}
Aggregations