What's it?
HttpBatch is a script engine for http request,which is used for automated testing,crawler and so on.
Features
- Base on groovy,flexible
- Convenient and efficient
- Needless to compile
Usage
- Installation
Download the latest package(https://github.com/kasonyang/httpbatch/releases)
unzip, then add the path httpbatch/bin
to system environment PATH
- Run
- Create a new file with the name "example.hb"
go "http://www.baidu.com"
testEquals 200,$$.statusCode//whether the status code is 200?
def text = $$.text //get the response as text
println text //output the response
- Execute the script file
$ httpbatch example.hb
Examples
Post form
post "YOUR_URL" ,[user:'test',password:'test'],{
def statusCode = $$.statusCode
def text = $$.text //get the text
testEquals 200,statusCode
}
RESTful test
post "YOUR_URL",[paramName:'paramValue'],{
def json = $$.json//get the result as json
testEquals "Hello Word!",json.message
}
Set request header
beforeGo{ req ->
req.addHeader("Accept","application/json")
}
go "YOUR_URL",{
//do something
}
Pre-defined variables and methods
- variables
$$
the latest response.You can use it as an instance oforg.apache.http.client.methods.CloseableHttpResponse
- methods visit the api