canoo web test 快速入门

这是我们实现Agile development重要的一环.

(0) 安装

— download jave runtime (JRE)
— download webtest: http://webtest.canoo.com/webtest/build.zip, 解压到本地目录 <WEBTEST_HOME> (例如, C:\webtest)
— Add <WEBTEST_HOME>\bin to your PATH (控制面板–>系统–>高级–>环境变量)
–cd <WEB_HOME>\doc\samples 运行:
webtest -buildfile installTest.xml

一般来说,运行test cases用这样的语法:
webtest -buildfile <testcasefile>

例如,

webtest -buildfile mytest.xml

(1)test cases目录结构

建立一个目录叫testcases,testcases放到该目录下面

testcases
includes: 包含文件
properties: 存储一些与环境相关或常变化的测试数据
modules:小的可重用的测试模块
UseCases : 对应于use cases的test cases
TestResults: 存放测试结果和报告.

建立一个 web directory 指向TestResults目录. 例如, http://localhost/TestResults/testresult.html 就可以看见测试报告.

(2) 简单例子:

附件这个简单test case是验证海归网登陆的:

把这个文件存为mytest1.xml, (去掉.doc后缀), 放到TestCases目录下,把name="webtest.home" location="E:/canoo" 中location的值改为你的canoo web test的根目录.

然后运行 webtest -buildfile mytest1.xml;运行完毕后到http://localhost/TestResults/results.html看测试报告.

最后一步应该是失败的,因为crazytang的password不对. 要想测试测试成功需要把上面login.ok.password的值改成crazytang的密码.

注:测试报告格式和语言可以通过XSLT定制;回头我们会修改一下现在的报告格式,并且加上email通知功能.

(3) Canoon WebTest 的功能简介

背景: canoo webtest是用java 编写的,我们上述的例子用 ant 执行.(ant本身是一个java build tool, 相当于make,但比make强的多)

它是一个web acceptance工具,而不是一个junit/htmlunit/phpunit之类的unit test工具,也就是说进行黑箱测试. 在用于开发时.需要预先根据
详细需求编写test cases(实际上也是use cases)把期望的web site什么样子有什么功能表达出来.

test cases是xml格式的,一般来说需要手工编写 (如果是对现有网站测试,可以用工具自动把用户手工测试的过程记录下来自动生成test cases,但对于新项目开发来说没有什么用处);

(4)test case编写入门

看看上面的简单例子.
每个<webtest> 元素代表一个 web session,里面包括<config>和<steps>. 前者定义访问的网站属性,后者是一系列测试的步骤,例如采取什么行动(点击button,设置cookie等),或者验证
返回页面(标题,内容,图象, response code等等);每个步骤都有一个相对应的webtest step. webtest当前所有支持的步骤主要见见:

http://webtest.canoo.com/webtest/manual/syntaxCore.html
http://webtest.canoo.com/webtest/manual/syntaxExtension.html

此外还有关于email/pdf/excel等的验证,config等的语法,详见手册: http://webtest.canoo.com/webtest/manual/manualOverview.html

(5) property, 包含文件等:

可以定义类似变量的property, 例如我上面简单例子中引用的${user}, ${login.ok.password}等都是在文件开始定义的properties.详细的propeties用法
见http://webtest.canoo.com/webtest/manual/properties.html

test cases可以由许多可重用的模块组成,这样易于维护减少冗余. 详细请见: http://webtest.canoo.com/webtest/manual/samples.html.

(6) 如果有必要直接在数据库中准备测试数据,(例如测试前需要建立一批用户)可以用与SQLUNIT结合实现:

详见 http://webtest.canoo.com/webtest/manual/sqlunit.html

(7)这里有些用户贡献的工具或测试步骤: http://webtest-community.canoo.com/wiki/space/Contributions+and+Uploads

(8) 我们会设置一个cron job(scheduled task)每夜自动运行所有test cases.

(9) test cases也存入SVN中.

About: mmpower

Software Architect & Soccer Fan 黑超白袜 = IT 民工 + 摇滚大叔


Leave a Reply

Your email address will not be published. Required fields are marked *