15

有没有人尝试将 Dojo DOH 单元测试与 Jenkins 集成?

我想做以下事情,但如果这已经完成,我不想重新发明它。所以,我在想:

  1. 从 Jenkins 的构建后步骤开始 DOH 测试并等待结果
  2. 在无头浏览器(例如 Crowbar)中自行运行测试
  3. 从 Crowbar 返回的 HTML 中解析成功/错误计数
  4. 查找(或编写)一个 Jenkins 插件,该插件将 (a) 如果测试失败,则构建失败,(b) 呈现测试结果,(c) 可能将结果集成到 CI 游戏插件中

问题:

  1. 以前有这样做过吗?
  2. 你看到上面的大纲有什么问题吗?
  3. 您是否知道有帮助的 Jenkins 插件,还是我必须自己构建?
4

3 回答 3

3

1. Automated Dojo testing - DOH & Selenium-RC (Rob Coup - 2008/01/03)

Plan:

  • Have a config file defining which browsers to launch, which machines they're on, and what tests to run.
  • Launch each browser via Selenium-RC
  • Run the tests via the normal DOH browser runner.
  • Use Selenium to extract the results from DOH.
  • Collate the results from the various browsers and produce something useful.

Solution:

  • Drop seleniumRunner.js, seleniumRunner.config.js, seleniumRunner.sh (or the .bat if you're on Windows), and selenium-java-client-driver.jar into util/doh/ in your Dojo install.
  • Put selenium-server.jar on each test machine, then run java -jar selenium-server.jar -multiWindow so it listens for the browser-control messages.
  • Edit seleniumRunner.config.js and change browsers and rootUrl to match your setup. The rootUrl needs to be reachable from each test machine.
  • run ./seleniumRunner.sh seleniumRunner.config.js from util/doh/ on your workstation
  • It'll load the config, fire up the browsers on each machine, run the unit tests from Dojo core, and print the pass/fail/error stats for each.
  • Each browser is kicked off and monitored in a separate thread (not strictly necessary but too cool to resist doing).

Issues:

  • unless I ran the selenium server in multiWindow mode Safari and Firefox would pop up Print dialogs (!?!) whenever the test page was loaded. But Safari never initialised the test page if it was in multiWindow mode. On OSX and Windows. gah.
  • Opera on OSX didn't set up the Selenium proxy properly (localhost:4444 for reference).
  • IE didn't like doing a dojo.connect() via the selenium javascript commands for some reason.

2. Seems reasonable to me.

3. Jenkins Selenium plugin

This plugin turns your Jenkins cluster into a Selenium2 Grid cluster, so that you can utilize your heterogeneous Jenkins clusters to carry out Selenium tests. This plugin is a turn-key solution — no additional installation nor configuration is necessary to make it work. The plugin installs Selenium Grid on all the slaves automatically and set up a grid on its own.

于 2012-01-13T02:16:02.447 回答
2

为了运行 DOH 测试,我开发了一个集成到 ci 中并且可以启动浏览器的工具。

http://codeblog.bigbrowser.net/dojo-testing-doh-with-continuous-integration/

也许你也可以试试这个。

我已经解释了在哪里下载以及如何运行它。

于 2012-09-14T15:51:01.150 回答
1

这是我使用 HTMLUnit 的方法。不需要硒。

它作为常规的 JUnit 测试运行(可以很容易地由 CI 服务器自动运行),如果测试失败,它会打印出 DOH 日志。

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) && runningTime < 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"));
  }

}

下面是runTests.html 的内容。它基本上只是重定向到 DOJO 测试运行器,参数特定于我们要测试的目录中的测试。

这只是一种构造事物的好方法,您也可以在 JUnit 测试的 PATHNAME 字段中指定此 URL。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
    <title>Dojox Unit Test Runner</title>
      <!--The "testModule" param tells the runner which test module to run-->
      <!--The "paths" param adds our dojo module paths, otherwise it would just look in the default dojo modules for code to test.-->
    <meta http-equiv="REFRESH" content="0;url=../../../../dojo-release-1.7.2-src/util/doh/runner.html?testModule=util.tests.module&paths=util,../../mystuff/dojo/util;mystuff,../../mystuff/dojo"></HEAD>
    <BODY>
        Redirecting to D.O.H runner.
    </BODY>
</HTML> 
于 2012-06-05T03:26:54.340 回答