如何通过 Jenkins 运行 Dojo DOH 单元测试?

发布于 2024-10-21 01:58:49 字数 410 浏览 1 评论 0原文

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

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

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

问题:

  1. 之前是否这样做过?
  2. 你觉得上面的大纲有什么问题吗?
  3. 你知道有一个 Jenkins 插件可以提供帮助吗?或者我必须构建自己的插件?

Has anyone tried integrating Dojo DOH unit-tests with Jenkins?

I'd like to do the following, but don't want to reinvent it if this has already been done. So, I'm thinking:

  1. Kick off the DOH-tests from a post-build step in Jenkins and wait for the results
  2. Run the tests themselves in a headless-browser (e.g. Crowbar)
  3. Parse the succes/error-count from the HTML returned by Crowbar
  4. Find (or write) a Jenkins plugin that will (a) fail the build if there are failing tests, (b) render the test results, (c) possibly integrate results into the CI game plugin

Questions:

  1. Has this been done before?
  2. Do you see any issues with the outline above?
  3. Do you know of a Jenkins plugin that will help, or will I have to build my own?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷情 2024-10-28 01:58:49

1. 自动化 Dojo 测试 - DOH 和 Dojo Selenium-RC (Rob Coup - 2008/01/03)

计划:

  • 有一个配置文件,定义要启动哪些浏览器、它们在哪些机器上以及要运行哪些测试。
  • 通过 Selenium-RC 启动每个浏览器
  • 通过普通的 DOH 浏览器运行程序运行测试。
  • 使用 Selenium 从 DOH 中提取结果。
  • 整理各种浏览器的结果并生成有用的内容。

解决方案:

  • 删除 seleniumRunner.js、seleniumRunner.config.js、seleniumRunner.sh(如果使用的是 Windows,则删除 .bat)和 selenium- java-client-driver.jar 到 Dojo 安装中的 util/doh/ 中。
  • selenium-server.jar放在每台测试机器上,然后运行java -jar selenium-server.jar -multiWindow以便它侦听浏览器控制消息。
  • 编辑seleniumRunner.config.js并更改浏览器rootUrl以匹配您的设置。 rootUrl 需要能够从每台测试机器访问。
  • 从工作站上的 util/doh/ 运行 ./seleniumRunner.sh seleniumRunner.config.js
  • 它将加载配置,启动每台计算机上的浏览器,从 Dojo 核心运行单元测试,并打印每台计算机的通过/失败/错误统计信息。
  • 每个浏览器都会在单独的线程中启动和监控(不是绝对必要的,但太酷了,无法抗拒这样做)。

问题:

  • 除非我在多窗口模式下运行 selenium 服务器,否则每当测试页打开时,Safari 和 Firefox 都会弹出打印对话框(!?!)
    已加载。但 Safari 从未初始化过测试页面(如果是)
    多窗口模式。在 OSX 和 Windows 上。啊。
  • OSX 上的 Opera 未正确设置 Selenium 代理(localhost:4444 供参考)。
  • 出于某种原因,IE 不喜欢通过 selenium javascript 命令执行 dojo.connect()

2. 我觉得很合理。

3. Jenkins Selenium 插件

这个插件将你的 Jenkins 集群变成 Selenium2 Grid 集群,
这样你就可以利用你的异构 Jenkins 集群来承载
进行硒测试。该插件是一个交钥匙解决方案 - 无需额外
无需安装或配置即可使其工作。这
插件自动在所有从站上安装 Selenium Grid 并设置
自己建立一个网格。

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.

浮华 2024-10-28 01:58:49

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

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

也许你也可以尝试一下。

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

For running the D.O.H tests i have developed a tool which integrates into ci and can start the browser.

http://codeblog.bigbrowser.net/dojo-testing-d-o-h-with-continuous-integration/

Maybee you can give this also a try.

I have explained there where to download and how to run it.

行至春深 2024-10-28 01:58:49

以下是我使用 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> 

Here's how I did it with HTMLUnit. No Selenium required.

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.

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

}

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.

It's just a nice way to structure things, you could alternatively have specified this URL in the PATHNAME field in the JUnit test.

<!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> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文