Search in sources :

Example 16 with BuggyWebDriver

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

the class ConsoleTest method assertString.

/**
 * @throws Exception if the test fails
 */
@Test
@BuggyWebDriver
public void assertString() throws Exception {
    final String html = "<html>\n" + "<body>\n" + "<script>\n" + "  number = 1;\n" + "  console.assert(number % 2 === 0, '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: 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)

Example 17 with BuggyWebDriver

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

the class ConsoleTest method errorCall.

/**
 * @throws Exception if the test fails
 */
@Test
@BuggyWebDriver
public void errorCall() throws Exception {
    final String html = "<html>\n" + "<body>\n" + "<script>\n" + "  function foo() {\n" + "    (undefined || console.error)('he ho');\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.contains("he ho"));
}
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 18 with BuggyWebDriver

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

the class ConsoleTest method assertParams.

/**
 * @throws Exception if the test fails
 */
@Test
@BuggyWebDriver
public void assertParams() throws Exception {
    final String html = "<html>\n" + "<body>\n" + "<script>\n" + "  console.assert(false, 'the word is %s', '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);
    assertTrue(logEntry.getMessage(), logEntry.getMessage().contains("Assertion failed: the word is foo"));
}
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 19 with BuggyWebDriver

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

the class XMLHttpRequest2Test method xhrCallbackBeforeTimeout.

/**
 * Ensures that XHR callback is executed before a timeout, even if it is time
 * to execute this one.
 * @throws Exception if an error occurs
 */
@Test
@Alerts("hello in timeout")
@BuggyWebDriver(FF_ESR = "in timeouthello", FF = "in timeouthello", IE = "in timeouthello")
public // IEDriver catches "in timeout", "hello" but real IE gets the correct order
void xhrCallbackBeforeTimeout() throws Exception {
    final String html = "<html><head><script>\n" + "function wait() {\n" + "  var xhr = new XMLHttpRequest();\n" + "  xhr.open('GET', '/delay200/foo.txt', false);\n" + "  xhr.send('');\n" + "}\n" + "function doTest() {\n" + "  setTimeout(function() { document.title += ' in timeout'; }, 5);\n" + "  wait();\n" + "  var xhr2 = new XMLHttpRequest();\n" + "  var handler = function() {\n" + "    if (xhr2.readyState == 4)\n" + "      document.title += xhr2.responseText;\n" + "  }\n" + "  xhr2.onreadystatechange = handler;\n" + "  xhr2.open('GET', '/foo.txt', true);\n" + "  xhr2.send('');\n" + "  wait();\n" + "}\n" + "setTimeout(doTest, 10);\n" + "</script></head><body></body></html>";
    getMockWebConnection().setDefaultResponse("hello", MimeType.TEXT_PLAIN);
    final WebDriver driver = loadPage2(html);
    assertTitle(driver, getExpectedAlerts()[0]);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 20 with BuggyWebDriver

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

the class Window3Test method opener.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts({ "null", "one", "two", "three" })
@BuggyWebDriver(IE = { "undefined", "one", "two", "three" })
public void opener() throws Exception {
    final URL urlThird = new URL(URL_FIRST, "third/");
    final String firstContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + "function test() {\n" + "  alert(window.opener);\n" + "  alert('one');\n" + "  open('" + URL_SECOND + "', 'foo');\n" + "}\n" + "function calllog(text) {\n" + "  alert(text);\n" + "}\n" + "</script></head><body onload='test()'>\n" + "</body></html>";
    final String secondContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>Second</title><script>\n" + "function test() {\n" + "  opener.calllog('two');\n" + "  document.form1.submit();\n" + "}\n" + "</script></head><body onload='test()'>\n" + "<form name='form1' action='" + urlThird + "' method='post'><input type='submit'></form>\n" + "</body></html>";
    final String thirdContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>Third</title><script>\n" + "function test() {\n" + "  opener.calllog('three');\n" + "}\n" + "</script></head><body onload='test()'>\n" + "</body></html>";
    getMockWebConnection().setResponse(URL_SECOND, secondContent);
    getMockWebConnection().setResponse(urlThird, thirdContent);
    final WebDriver driver = loadPageWithAlerts2(firstContent);
    assertTitle(driver, "First");
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) URL(java.net.URL) HtmlPageTest(com.gargoylesoftware.htmlunit.html.HtmlPageTest) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

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