mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
feat: post json with functions
This commit is contained in:
@@ -12,22 +12,31 @@ func TestCaseCallFunction(t *testing.T) {
|
|||||||
Name: "run request with functions",
|
Name: "run request with functions",
|
||||||
BaseURL: "https://postman-echo.com",
|
BaseURL: "https://postman-echo.com",
|
||||||
Verify: false,
|
Verify: false,
|
||||||
|
Variables: map[string]interface{}{
|
||||||
|
"n": 5,
|
||||||
|
"a": 12.3,
|
||||||
|
"b": 3.45,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
TestSteps: []httpboomer.IStep{
|
TestSteps: []httpboomer.IStep{
|
||||||
httpboomer.Step("get with params").
|
httpboomer.Step("get with params").
|
||||||
WithVariables(map[string]interface{}{
|
|
||||||
"n": 5,
|
|
||||||
"a": 12.3,
|
|
||||||
"b": 3.45,
|
|
||||||
}).
|
|
||||||
GET("/get").
|
GET("/get").
|
||||||
WithParams(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
|
WithParams(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
|
||||||
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
|
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
|
||||||
Extract().
|
Extract().
|
||||||
WithJmesPath("body.args.foo1", "varFoo1").
|
WithJmesPath("body.args.foo1", "varFoo1").
|
||||||
Validate().
|
Validate().
|
||||||
|
AssertEqual("status_code", 200, "check status code").
|
||||||
AssertLengthEqual("body.args.foo1", 5, "check args foo1").
|
AssertLengthEqual("body.args.foo1", 5, "check args foo1").
|
||||||
AssertEqual("body.args.foo2", "12.3", "check args foo2"), // notice: request params value will be converted to string
|
AssertEqual("body.args.foo2", "12.3", "check args foo2"), // notice: request params value will be converted to string
|
||||||
|
httpboomer.Step("post json data with functions").
|
||||||
|
POST("/post").
|
||||||
|
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
|
||||||
|
WithJSON(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
|
||||||
|
Validate().
|
||||||
|
AssertEqual("status_code", 200, "check status code").
|
||||||
|
AssertLengthEqual("body.json.foo1", 5, "check args foo1").
|
||||||
|
AssertEqual("body.json.foo2", 12.3, "check args foo2"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,8 @@ func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) {
|
|||||||
v = append(v, data)
|
v = append(v, data)
|
||||||
}
|
}
|
||||||
if step.Request.JSON != nil {
|
if step.Request.JSON != nil {
|
||||||
v = append(v, req.BodyJSON(step.Request.JSON))
|
jsonData := parseData(step.Request.JSON, step.Variables)
|
||||||
|
v = append(v, req.BodyJSON(jsonData))
|
||||||
}
|
}
|
||||||
|
|
||||||
for cookieName, cookieValue := range step.Request.Cookies {
|
for cookieName, cookieValue := range step.Request.Cookies {
|
||||||
|
|||||||
Reference in New Issue
Block a user