Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's how I did it with HTMLUnit. No Selenium required.</p> <p>It runs as a regular JUnit test (which can easily be run automatically by your CI Server), and prints out the DOH log if there is a test failure.</p> <pre><code>public class JavascriptTest { private static final int MAX_RUNNING_TIME = 10 * 1000; //The test runner public static final String PATHNAME = "src/main/webapp/library/mystuff/dojo/util/tests/runTests.html"; //Runs all of the Dojo Objective Harness (D.O.H.) javascript tests. //The tests are currently grouped into test modules, and the parent module is "util.tests.module" (in module.js) //As you can see in the URL pathname, we pass that module name to the testRunner and it runs all the javascript tests. @Test public void runAllJavascriptTests() throws Exception { final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8); final HtmlPage page = webClient.getPage("file://" + new File(PATHNAME).getAbsolutePath()); waitForTestsToRun(webClient, page); String log = page.getElementById("logBody").asText(); assertTrue(log, page.asText().contains("WOOHOO!!")); //D.O.H. will display WOOHOO!! if all tests are successful. } private void waitForTestsToRun(WebClient webClient, HtmlPage page) { webClient.waitForBackgroundJavaScript(500); int runningTime = 0; while(testsAreRunning(page) &amp;&amp; runningTime &lt; MAX_RUNNING_TIME){ webClient.waitForBackgroundJavaScript(500); runningTime += 500; } } private boolean testsAreRunning(HtmlPage page) { //Check if the "Tests Running" div is visible. return "".equals(page.getElementById("playingMsg").getAttribute("style")); } } </code></pre> <p>And below is the content of runTests.html. It basically just redirects to the DOJO test runner, with parameters specific to the tests in the directory we want to test. </p> <p>It's just a nice way to structure things, you could alternatively have specified this URL in the PATHNAME field in the JUnit test.</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Dojox Unit Test Runner&lt;/title&gt; &lt;!--The "testModule" param tells the runner which test module to run--&gt; &lt;!--The "paths" param adds our dojo module paths, otherwise it would just look in the default dojo modules for code to test.--&gt; &lt;meta http-equiv="REFRESH" content="0;url=../../../../dojo-release-1.7.2-src/util/doh/runner.html?testModule=util.tests.module&amp;paths=util,../../mystuff/dojo/util;mystuff,../../mystuff/dojo"&gt;&lt;/HEAD&gt; &lt;BODY&gt; Redirecting to D.O.H runner. &lt;/BODY&gt; &lt;/HTML&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload