1

HtmlUnit is causing an integration test to fail because of a javascript issue in jquery. I am trying to figure out how to disable javascript checking in this context. I know there is client.getOptions().setThrowExceptionOnScriptError(false) option, but don't know how to get to that in this context. Here is the test:

@Test
public void test() {
    running(testServer(3333, fakeApplication(inMemoryDatabase())), HTMLUNIT, new Callback<TestBrowser>() {
        public void invoke(TestBrowser browser) {
            browser.goTo("http://localhost:3333");
            assertTrue(browser.pageSource().contains("Sears Home Services Platform Admin"));
        }
    });
}

The error I'm getting is:

[error] - com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter - runtimeError: message=[An invalid or illegal selector was specified (selector: ':checked' error: Invalid selector: *:checked).] sourceName=[http://localhost:3333/webjars/jquery/1.11.1/jquery.min.js] line=[2] lineSource=[null] lineOffset=[0]
Khorkhe
  • 1,024
  • 1
  • 11
  • 26

2 Answers2

1

The answer to this question Fluentlenium crashes on jquery in play framework suggests to replace HTMLUNIT by new HtmlUnitDriver()

This solved it for me.

your code would look something like:

@Test
public void test() {
    running(testServer(3333, fakeApplication(inMemoryDatabase())), new HtmlUnitDriver(), new Callback<TestBrowser>() {
        public void invoke(TestBrowser browser) {
            browser.goTo("http://localhost:3333");
            assertTrue(browser.pageSource().contains("Sears Home Services Platform Admin"));
        }
    });
}

According to him, this would disable javascript completely in your tests, as HTMLUNIT includes javascript and is finding errors in the jQuery source.

Community
  • 1
  • 1
Khorkhe
  • 1,024
  • 1
  • 11
  • 26
0

Try these below

        LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
        java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
        java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF);
        java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter").setLevel(Level.OFF);
        java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject").setLevel(Level.OFF);
        java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument").setLevel(Level.OFF);
        java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.html.HtmlScript").setLevel(Level.OFF);
        java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript.host.WindowProxy").setLevel(Level.OFF);
        java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
        java.util.logging.Logger.getLogger("org.apache").setLevel(Level.OFF);
Arya
  • 8,473
  • 27
  • 105
  • 175
  • I tried using this snippet in the BeforeAll() function of the test that uses TestBrowser / WithBrowser, but the StrictErrorReporter errors remained. Using play framework 2.4 with Scala. Changing jquery versions did not get rid of the errors either. Any suggestions? – Khorkhe Dec 07 '15 at 21:22