最有价值的是最后一段,介绍了许多测试工具
There’s a lot of misinformation out there regarding web application test tools, so I’ve decided to post a series of short articles comparing some of the open source options available here in Java-land, circa 2007. The first of these articles will focus on HtmlUnit and HttpUnit. Please take my criticism and praise with a grain of salt, as I’m a committer to the HtmlUnit project and thus probably biased. Nevertheless, I will do my best to be objective. I may even overcompensate in the other direction!
Confusion
The HtmlUnit and HttpUnit projects are often confused due to the similarity of their names. And the similarity doesn’t end there: they are both open source projects; they are both 100% Java frameworks, rather than drivers for native browsers like IE or Firefox; and they are both fairly mature projects.
This confusion is compounded by the fact that many test frameworks which once used HttpUnit under the covers have since switched to using HtmlUnit, mainly in order to benefit from its excellent JavaScript support. Examples include JWebUnit, whose FAQ briefly explains the switch, and Canoo WebTest, which switched in 2004 due to JavaScript support issues and an unresponsive development team [1].
HttpUnit
HttpUnit is the granddaddy web app testing framework. Started in the summer of 2000 by Russ Gold [2], it was the first project to focus on this niche area. The project has since stagnated somewhat, with nearly 40% of bugs remaining open, some of them nearly three years old. Its latest maintenance release is about a year and a half old.
The API is fairly low-level, modeling web interactions at something approaching the HTTP request and response level. The following is a slightly modified example from the HttpUnit Cookbook:
WebConversation wc = new WebConversation();
WebResponse resp = wc.getResponse("http://www.google.com/");
WebLink link = resp.getLinkWith("About Google");
link.click();
WebResponse resp2 = wc.getCurrentPage();
As you can see, things center around WebConversations, WebRequests and WebResponses. Unfortunately, any page with a decent amount of JavaScript is likely to break HttpUnit, and you can absolutely forget testing any pages which use third party JavaScript libraries.
Nevertheless, HttpUnit continues to generate 3,000 to 4,000 downloads per month. A good analogy, if I may be allowed a brief subjective comment, is that HttpUnit is to the web app testing world what Struts is to the web app framework world: there are many “better” options out there, but it just won’t go away!
HtmlUnit
HtmlUnit is itself a fairly old project, having been started by Mike Bowler in early 2002. Mike has since ceased active development, but the project currently boasts 3 or 4 active developers and a total of seven committers (whereas HttpUnit remains a one-man show). It averages about three releases per year, and has seen increased developer activity in the past six months or so, especially in the area of JavaScript support.
HtmlUnit’s API is a bit more high-level than HttpUnit’s, modeling web interaction in terms of the documents and interface elements which the user interacts with:
WebClient wc = new WebClient();
HtmlPage page = (HtmlPage) wc.getPage("http://www.google.com");
HtmlForm form = page.getFormByName("f");
HtmlSubmitInput button = (HtmlSubmitInput) form.getInputByName("btnG");
HtmlPage page2 = (HtmlPage) button.click();
As you can see, the code centers around WebClients, as well as pages, links, forms, buttons, etc. Pages with a modicum of custom JavaScript will probably work when tested with HtmlUnit. Unfortunately, pages which use third party libraries might or might not work when tested via HtmlUnit. As of the current version, Prototype, Script.aculo.us, DWR and jQuery are known to be supported fairly well, Dojo is a bit of an unknown, YUI is known to be unsupported, and GWT is known to work with fairly simple applications. Most of this compatibility has been achieved in the past two or three releases, so obviously things are fairly fluid.
Conclusion
If you’re using HttpUnit for legacy reasons, it’s a fairly solid package, but don’t expect to get much support when you need to report a bug or submit a patch for a new feature. If you’re starting a new project and are trying to decide between these two frameworks, HtmlUnit wins hands down. It has the features, the community and the momentum.
Of course, if you’re considering web application testing tools, you’re probably looking at more than just these two options. Canoo WebTest, TestMaker, JWebUnit, Selenium, WebDriver and JMeter are all likely to be on your list. Depending on your project budget and requirements, Squish and Mercury QTP may also be under consideration. If that’s the case, stay tuned, because I intend to post a series of web app testing framework comparisons in the coming months — all of them involving HtmlUnit, of course!
[1] It’s interesting to note that both Marc Guillemot and I (two HtmlUnit committers) began by using HttpUnit, submitting patches for missing features — but settled on HtmlUnit when the patches were not applied in a timely manner.
[2] The HttpUnit website states that Russ currently works for Oracle, developing the OC4J application server. Coincidentally, this is the production application server we’re using at my day job. Thanks, Russ!
Powered by ScribeFire.
分享到:
相关推荐
在本项目中,我们关注的是一个基于HTTPUnit的Web工程实例,它包含了源码和必要的依赖包,能够处理异步数据加载。这个工程是用Java 1.8或更高版本编译并运行的,旨在帮助开发者理解如何在Web应用程序中进行HTTP请求...
HTTPUnit 是一个Java库,主要用于自动化Web应用程序的测试。它提供了对HTTP协议的模拟,使得开发者可以在不依赖浏览器的情况下测试Web应用。这个标题提到的是HTTPUnit的2.21版本的jar包及其关联的jar包。在Java开发...
HTMLUnit是一个Java库,它提供了一个无头浏览器的模拟,用于自动化Web页面的测试和抓取。这个"giat-htmlunit_test.rar"压缩包显然包含了与使用HTMLUnit进行JavaScript交互和网页抓取相关的代码示例或测试用例。在...
HTMLUnit是一款强大的无头Web客户端库,主要用于网页的单元测试。它模拟了一个浏览器,能够执行JavaScript,解析HTML,处理CSS,以及与网页上的各种元素进行交互。这个“htmlunit-2.3.zip”压缩包包含了运行和使用...
HTMLUnit是一个强大的Java库,它模拟了一个无头Web浏览器,主要用于自动化测试和网页抓取。在版本2.23的zip文件中,我们主要关注HTMLUnit的核心功能和它如何帮助开发者处理HTML内容。 HTMLUnit的核心是基于Jakarta ...
HTMLUnit是一个Java库,它提供了一个无头浏览器模拟器,用于自动化Web页面的导航和交互。这个库在测试、数据抓取以及不需图形用户界面的场景中非常有用。"htmlUnit所需jar包"的标题表明这是一个包含HTMLUnit运行所需...
HTMLUnit是一款功能强大的Java库,它模拟了一个无头Web浏览器,允许开发者在没有真实浏览器环境的情况下执行JavaScript,处理Ajax请求,以及与网页进行交互。这个库对于自动化测试、数据抓取和网页爬虫项目非常有用...
HTMLUnit是一个Java库,它提供了一个无头浏览器模拟器,用于自动化Web页面的测试和交互。这个"htmlunit基本jar包"包含了运行HTMLUnit所需的所有核心组件,无需通过Maven来管理和依赖。这意味着用户可以直接在项目中...
HTMLUnit是一个Java库,它模拟了一个无头Web浏览器,用于自动化网页测试和抓取。它提供了JavaScript支持,能够处理AJAX请求,使开发者能够在没有实际图形界面的情况下与网页交互。这个"htmlunit-2.1.5源码"包包含了...
HTMLUnit是一个基于Java的无头Web客户端库,它模拟了一个完整的浏览器,但不涉及实际的图形用户界面。这个“htmlunit-2.19-bin”压缩包包含了HTMLUnit的二进制版本,允许开发者在Java应用程序中进行网页自动化测试和...
HTMLUnit是Java编程语言中的一款无头Web浏览器库,它模拟了浏览器的行为,但不涉及图形用户界面。这个工具主要用于自动化测试和网络爬虫,因为它能够解析HTML、执行JavaScript,并与网页上的各种元素进行交互。在...
HtmlUnit 是一个强大的Java库,它模拟了一个无头Web浏览器,允许开发者进行自动化测试和网页抓取。在HtmlUnit 2.8版本中,你可以利用它来执行JavaScript、处理Ajax请求,以及与网页上的各种元素交互,而无需实际运行...
HTMLUnit是一款强大的Java库,它模拟了一个无头Web浏览器,主要用于自动化Web测试和网页抓取。这个参考文档是关于HTMLUnit的API详细说明,对于开发者来说是理解和使用HTMLUnit的重要资源。下面,我们将深入探讨...
HTMLUnit是一个Java库,模拟一个无头Web浏览器,主要用于自动化测试和网页抓取。它能够解析HTML、执行JavaScript,并返回用户可以操作的DOM元素。在Java应用中使用HTMLUnit,通常需要依赖一系列的JAR(Java Archive...
HTMLUnit是一个功能强大的Java库,它模拟了一个无头Web浏览器,允许开发者进行自动化网页测试和网络爬虫工作。这个库的核心在于它能够解析HTML、执行JavaScript,并与网页上的元素进行交互,而无需真实地打开一个...
HTMLUnit是一个强大的Java库,它模拟了一个无头Web浏览器,主要用于自动化Web测试和网页抓取。这个"htmlunit-2.27-bin"压缩包包含了HTMLUnit版本2.27的所有必要组件,使得用户能够在没有图形界面的情况下执行...
HTMLUnit是一个Java库,它提供了一个无头浏览器模拟器,用于自动化Web页面的测试和抓取。这个库的核心功能是能够解析、渲染和执行JavaScript,从而使得开发者可以在没有实际浏览器环境的情况下,对网页进行功能测试...
HtmlUnit是Java编程语言中的一款无头浏览器模拟库,它允许开发者在没有真实浏览器环境的情况下进行Web应用程序的测试和自动化。最新版HtmlUnit 2.22提供了对现代Web技术的强大支持,包括JavaScript、Ajax以及各种...
源码包中的文件结构还包括单元测试,位于`src/test/java`目录下,这些测试用例展示了如何使用HTMLUnit进行各种操作,同时也对库的内部逻辑进行了验证。通过阅读和运行这些测试,你可以更好地理解HTMLUnit的工作机制...
2. **JavaScript支持**:HTMLUnit可以解析和执行JavaScript代码,这对于现代Web应用来说是至关重要的,因为许多动态网页依赖JavaScript来加载内容和实现交互。 3. **DOM操作**:通过HTMLUnit提供的API,开发者可以...