MCPcopy
hub / github.com/httprunner/httprunner / TestCaseExtractStepSingle

Function TestCaseExtractStepSingle

hrp/tests/extract_test.go:10–43  ·  view source on GitHub ↗

reference extracted variables for validation in the same step

(t *testing.T)

Source from the content-addressed store, hash-verified

8
9// reference extracted variables for validation in the same step
10func TestCaseExtractStepSingle(t *testing.T) {
11 testcase := &hrp.TestCase{
12 Config: hrp.NewConfig("run request with variables").
13 SetBaseURL("https://postman-echo.com").
14 SetVerifySSL(false),
15 TestSteps: []hrp.IStep{
16 hrp.NewStep("get with params").
17 WithVariables(map[string]interface{}{
18 "var1": "bar1",
19 "agent": "HttpRunnerPlus",
20 "expectedStatusCode": 200,
21 "jmespathFoo1": "body.args.foo1",
22 }).
23 GET("/get").
24 WithParams(map[string]interface{}{"foo1": "$var1", "foo2": "bar2"}).
25 WithHeaders(map[string]string{"User-Agent": "$agent"}).
26 Extract().
27 WithJmesPath("status_code", "statusCode").
28 WithJmesPath("headers.\"Content-Type\"", "contentType").
29 WithJmesPath("$jmespathFoo1", "varFoo1").
30 Validate().
31 AssertEqual("$statusCode", "$expectedStatusCode", "check status code"). // assert with extracted variable from current step
32 AssertEqual("$contentType", "application/json; charset=utf-8", "check header Content-Type"). // assert with extracted variable from current step
33 AssertEqual("$varFoo1", "bar1", "check args foo1"). // assert with extracted variable from current step
34 AssertEqual("body.args.foo2", "bar2", "check args foo2").
35 AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
36 },
37 }
38
39 err := hrp.NewRunner(t).Run(testcase)
40 if err != nil {
41 t.Fatalf("run testcase error: %v", err)
42 }
43}
44
45// reference extracted variables from previous step
46func TestCaseExtractStepAssociation(t *testing.T) {

Callers

nothing calls this directly

Calls 14

NewConfigFunction · 0.92
NewStepFunction · 0.92
NewRunnerFunction · 0.92
SetVerifySSLMethod · 0.80
SetBaseURLMethod · 0.80
AssertEqualMethod · 0.80
WithJmesPathMethod · 0.80
GETMethod · 0.80
RunMethod · 0.65
ValidateMethod · 0.45
ExtractMethod · 0.45
WithHeadersMethod · 0.45

Tested by

no test coverage detected