51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 3493|回复: 2
打印 上一主题 下一主题

JwebUnit 入门

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2010-5-25 01:42:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
homepage
JWebUnit is a Java-based testing framework for web applications. It wraps existing testing frameworks such as HtmlUnit and Selenium with a unified, simple testing interface to allow you to quickly test the correctness of your web applications.


看下使用吧。
下载jar包
引入jwebunit-htmlunit-plugin-2.3.jar,jwebunit-core-2.3.jar
注意lib里面jar包也要引入

例子1(HtmlUnit)
  1. package com.test;

  2. import net.sourceforge.jwebunit.htmlunit.HtmlUnitTestingEngineImpl;
  3. import net.sourceforge.jwebunit.junit.WebTestCase;
  4. import net.sourceforge.jwebunit.junit.WebTester;
  5. import net.sourceforge.jwebunit.selenium.SeleniumTestingEngineImpl;


  6. public class ExampleWebTestCase extends WebTestCase {
  7.         private WebTester tester;
  8.    
  9.         public ExampleWebTestCase(String name) {
  10.       super(name);
  11.       tester = new WebTester();
  12.       HtmlUnitTestingEngineImpl engine = new HtmlUnitTestingEngineImpl();
  13.       //SeleniumTestingEngineImpl engine = new SeleniumTestingEngineImpl();
  14.       tester.setDialog(engine);
  15.       tester.getTestContext().setBaseUrl("http://www.google.cn/");
  16.     }

  17.      public void testSearch() throws Exception {
  18.             tester.beginAt("/");
  19.             tester.setTextField("q", "HtmlUnit");
  20.             tester.submit("btnG");
  21.             tester.clickLinkWithText("HtmlUnit");
  22.             tester.assertTitleEquals("HtmlUnit - Google 搜索");
  23.             tester.assertLinkPresentWithText("Get started");
  24.      }

  25. }
复制代码
例子2(selenium)
在运行这个例子这前:1.要下载selenium-jwebunit-plugin.jar包;2.启动selenium server;3.引入selenium-client.jar包
  1. package com.test;

  2. import net.sourceforge.jwebunit.htmlunit.HtmlUnitTestingEngineImpl;
  3. import net.sourceforge.jwebunit.junit.WebTestCase;
  4. import net.sourceforge.jwebunit.junit.WebTester;
  5. import net.sourceforge.jwebunit.selenium.SeleniumTestingEngineImpl;


  6. public class ExampleWebTestCase extends WebTestCase {
  7.         private WebTester tester;
  8.    
  9.         public ExampleWebTestCase(String name) {
  10.       super(name);
  11.       tester = new WebTester();
  12.       //HtmlUnitTestingEngineImpl engine = new HtmlUnitTestingEngineImpl();
  13.       SeleniumTestingEngineImpl engine = new SeleniumTestingEngineImpl();
  14.       tester.setDialog(engine);
  15.       tester.getTestContext().setBaseUrl("http://www.google.cn/");
  16.     }

  17.      public void testSearch() throws Exception {
  18.             tester.beginAt("/");
  19.             tester.setTextField("q", "HtmlUnit");
  20.             tester.submit("btnG");
  21.             tester.clickLinkWithText("HtmlUnit");
  22.             tester.assertTitleEquals("HtmlUnit - Google 搜索");
  23.             tester.assertLinkPresentWithText("Get started");
  24.      }

  25. }
复制代码
这个工具没有怎么用,只是看到这个工具处理方面。在setup中来设置用什么测试工具来执行。在一个项目中使用多种测试工具时,是否有参考意义呢?
用htmlunit是没有界面,明显比selenium要快。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2010-5-25 11:01:37 | 只看该作者
多谢分享~!
回复 支持 反对

使用道具 举报

该用户从未签到

3#
发表于 2010-5-26 11:26:10 | 只看该作者
顶一下
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-12 13:11 , Processed in 0.069915 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表