mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 19:39:44 +08:00
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package postman_echo
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/httprunner/httpboomer"
|
|
)
|
|
|
|
func TestCaseExtractStep(t *testing.T) {
|
|
testcase := &httpboomer.TestCase{
|
|
Config: httpboomer.TConfig{
|
|
Name: "run request with variables",
|
|
BaseURL: "https://postman-echo.com",
|
|
Verify: false,
|
|
},
|
|
TestSteps: []httpboomer.IStep{
|
|
httpboomer.Step("get with params").
|
|
WithVariables(map[string]interface{}{
|
|
"var1": "bar1",
|
|
"agent": "HttpBoomer",
|
|
"expectedStatusCode": 200,
|
|
}).
|
|
GET("/get").
|
|
WithParams(map[string]interface{}{"foo1": "$var1", "foo2": "bar2"}).
|
|
WithHeaders(map[string]string{"User-Agent": "$agent"}).
|
|
Extract().
|
|
WithJmesPath("status_code", "statusCode").
|
|
WithJmesPath("headers.\"Content-Type\"", "contentType").
|
|
WithJmesPath("body.args.foo1", "varFoo1").
|
|
Validate().
|
|
AssertEqual("$statusCode", "$expectedStatusCode", "check status code"). // assert with extracted variable
|
|
AssertEqual("headers.Connection", "keep-alive", "check header Connection").
|
|
AssertEqual("$contentType", "application/json; charset=utf-8", "check header Content-Type"). // assert with extracted variable
|
|
AssertEqual("$varFoo1", "bar1", "check args foo1"). // assert with extracted variable
|
|
AssertEqual("body.args.foo2", "bar2", "check args foo2").
|
|
AssertEqual("body.headers.\"user-agent\"", "HttpBoomer", "check header user agent"),
|
|
},
|
|
}
|
|
|
|
err := httpboomer.Test(t, testcase)
|
|
if err != nil {
|
|
t.Fatalf("run testcase error: %v", err)
|
|
}
|
|
}
|