0

Case

i'm trying to write a GWTTestCase for a certain class, used as a presenter for a history-browsing toolbar component i'm building.

Problem

one (or more) of the scripts apparently not being loaded for the jUnit testing environment. it all works fine when running the application (development mode), but when i try to run the test case, the application (web server as well as user agent) fails to load, and the following exception arouses (stacktrace is shortened for simplicity):

com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: Exception invoking jsxFunction_write  at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:601)   at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)  at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:499)     at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:595)   ... 41 more

...

Caused by: com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "Raphael" is not defined. (http://192.168.10.32:3692/com.gigaspaces.admin.webui.Gs_webui.JUnit/dracula/dracula_graffle.js#18) (http://192.168.10.32:3692/com.gigaspaces.admin.webui.Gs_webui.JUnit/com.gigaspaces.admin.webui.Gs_webui.JUnit.nocache.js#16)    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:601)

Relevant sources

here is the (ridiculously simple) GWTTestCase used:

public class HistoryBrowserTest extends GWTTestCase {

    @Override
    public String getModuleName() {
        return "com.gigaspaces.admin.webui.Gs_webui";
    }

    public void testHistoryBrowser() {
        assertTrue(true);
    }
}

Dependencies / context information

jUnit 4.10 is used as an external jar - and referenced successfully by the classpath and the .gwt.xml file is inheriting jUnit from GWT (<inherits name="com.google.gwt.junit.JUnit" />) the jUnit module is no longer inherited as the GWT team instructs not to - extending GWTTestCase will inherit it automatically.

i am using Raphael-GWT as a separate module. this module is also referenced in the main module's .gwt.xml file, and running fine under all other circumstances (development / production mode).

What have i tried

  • simplifying the case, e.g. stripping down the test case as seen above.
  • verifying inherited modules in the deployment descriptors.
  • varying jUnit's version, i.e. running both under V3 or V4, and manually compiled on each change.
  • looked up on google, as well as here on stackoverflow, with no avail.

More relevant information

Raphael lib is being used for a GWT wrapper i wrote for Dracula (a JS graph visualization library) so dracula_graffle.js originates there. enclosed is the .gwt.xml file source for a reference:

<module rename-to="gs_webui">

    <inherits name="com.google.gwt.user.User" />

    <!-- Other module inherits -->
    <inherits name="com.extjs.gxt.ui.GXT" />
    <inherits name="org.highchartsgwt.HighCharts" />
    <inherits name="gwtupload.GWTUpload" />
    <inherits name="com.hydro4ge.raphaelgwt.RaphaelGWT" />
    <inherits name="com.gigaspaces.gauge.Gs_gauges" />
    <inherits name="com.gigaspaces.graphs.Gs_graphs" />
    <inherits name="com.gigaspaces.svgcomponents.Gs_svg_components" />
    <inherits name="com.javaconstructors.colorpalette.Color_palette" />
    <inherits name="com.gigaspaces.jquerywidgets.Gs_jquery_widgets" />
    <inherits name="com.gigaspaces.codemirror_gwt.CodeMirror_GWT"/>

    <inherits name="com.google.gwt.i18n.I18N"/>
    <inherits name="com.google.gwt.query.Query" />

    <!-- I18N stuff, log configurations, and so forth... -->

    <entry-point class="com.gigaspaces.admin.webui.client.Gs_webui" />

    <!-- further source folder inherits... -->

</module>                                                                              
Eliran Malka
  • 15,821
  • 6
  • 77
  • 100

1 Answers1

1

How is Raphael loaded? It could be that the js file is never being pulled in to the html page being run in htmlunit.

Caused by: com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "Raphael" is not defined. (http://192.168.10.32:3692/com.gigaspaces.admin.webui.Gs_webui.JUnit/dracula/dracula_graffle.js#18) (http://192.168.10.32:3692/com.gigaspaces.admin.webui.Gs_webui.JUnit/com.gigaspaces.admin.webui.Gs_webui.JUnit.nocache.js#16)

This file doesn't appear to be used by RaphaelGWT, as it is not listed in their module file (seen here http://code.google.com/p/raphaelgwt/source/browse/trunk/src/com/hydro4ge/raphaelgwt/RaphaelGWT.gwt.xml).

This seems to be the source of your error - dracula_graffle.js (either line 18, or this is the 18th file loaded) cannot find the symbol Raphael, and since it is somehow required by your module, the app (in this case test) can't load without it. My quick guess is that it is either an HtmlUnit issue (HtmlUnit is what the gwt test cases run in, and only simulates a real browser) - you might try running this same test in a real browser, see http://code.google.com/webtoolkit/doc/latest/DevGuideTesting.html#Manual_Mode for more info. If that fails, then perhaps your app normally loads into an html page where some JS files have already been loaded, so this doesnt happen - those need to be loaded when testing the app as well, either using ScriptInjector in a setup method, or by adding them to your module file.


(After edits, comments)

Since the error occurred in manual mode as well, there isn't an error with htmlunit, but with dependencies in your code. From what appears to be a copy of dracula_graffle.js at http://code.google.com/p/synoptic/source/browse/synopticgwt/war/dracula_graffle.js?spec=svn2164f4b075bb0ed77f7b008bd113e04831196fec&r=2164f4b075bb0ed77f7b008bd113e04831196fec, line 18 is the first reference to Raphael, which should have defined when the raphael js file was loaded, which implies that it wasn't.

Running in manual mode with Firebug or the like running should show you an error in the console. Based on this, I think it is safe to say that something is different about the test case than the standard entrypoint+html page. The question is, what is different.

Are there any JS files, or script tags that run when the html page loads? GWTTestCases always run with just a very simple html page, and only load scripts defined in the module that you actually name in your .gwt.xml file. Are there any setup functions that are run as part of the entrypoint? Have you tried making a new, very simple html page, and writing a new, very simple EntryPoint for the module and using that instead? In the course of testing these things, I believe you will find some difference that is important in how your app works from how your test works.

If there isn't... the next annoying step is to run in manual mode again, with your app compiled in production model (see the same link, it should give details on how that might be done). Set firebug (or whatever tool you prefer) to stop on exceptions in Js, or simple set a breakpoint on line 18, when Raphael is used for the first time in dracula_graffle.js to see what scripts have loaded, and why Raphael isn't yet defined.

Colin Alworth
  • 17,801
  • 2
  • 26
  • 39
  • ok, some further details - the Raphael is being used for a GWT wrapper i wrote for Dracula (a JS graph visualization library) and those sources belong there. i've updated my question accordingly. – Eliran Malka Mar 18 '12 at 15:29
  • `ManualMode` didn't work for me (same result there), and as for the context running the app - it is self contained, as all modules are included as JAR files and compiled with the main module via `inherits` dependencies. thanks for your time and help regardless, i hope we can further investigate this. – Eliran Malka Mar 18 '12 at 15:59
  • Updated the answer with some more ideas based on your comments, edits, but so far it sounds like there is some important difference between a running _app_ and the _test_ that causes startup errors when trying to test. – Colin Alworth Mar 18 '12 at 21:19
  • this makes a lot of sense, but you're missing on the main point - i can't get to load the app whatsoever - the browser does not start. as your points are relevant, i'll go that route once more, to see if there are script dependencies not defined in the `.gwt.xml`. i assume digging enough (it's a very large project.. several developers involved) will finally pin point that one ill dependency. thanks for your efforts. – Eliran Malka Mar 19 '12 at 09:39
  • "i keep running into this problem - one (or more) of my scripts apparently not being loaded for the jUnit testing environment. it all works fine when running the application" - but now you say you cannot get the app to load? If you mean when running with Manual:1, the browser won't start on its own, that's true, you need to run the url it gives you, but if even the _app_ doesn't start, that is information the question didn't give. – Colin Alworth Mar 19 '12 at 12:12
  • that is the case indeed, and i edited the answer to be more descriptive. – Eliran Malka Mar 19 '12 at 13:05