geb for browser functional testing

Tue 17 August 2010
  • 装备 tags:
  • groovy
  • Testing
  • web published: true comments: true

虽然现在不做前段了,但是发现好的工具还是很兴奋。今天在twitter上看到Grails in Action的作者 @pledbrook 转了一个geb 0.4的消息,顺带看了一下这个工具
http://geb.codehaus.org

geb项目旨在创造一套groovy dsl帮助人们进行webapp的functional test。它是对selenium的封装,举例:
[cc lang="groovy"]
@Grapes([
@Grab('org.seleniumhq.selenium:selenium-firefox-driver:latest.release'),
@Grab('org.codehaus.geb:geb-core:latest.release')
])
import geb.*

println "Dependencies downloaded, ready for testing"
Browser.drive('http://sunng.info:8000/Pacajus'){
assert title== 'Pacajus'

assert $("p", 3).text() == 'Population: 41558'
} println "Tested, bye"
[/cc]

打开页面,执行断言。如果断言失败,driver方法会报null:
Caught: geb.error.DriveException: null

只要在命令行用groovy执行即可,grapes会搞定依赖关系。

很方便吧,文档上说还可以跟grails / junit等等集成,快去看看吧 http://geb.codehaus.org/manual/latest/index.html

The post is brought to you by lekhonee v0.7