reference extracted variables for validation in the same step
(t *testing.T)
| 8 | |
| 9 | // reference extracted variables for validation in the same step |
| 10 | func 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 |
| 46 | func TestCaseExtractStepAssociation(t *testing.T) { |
nothing calls this directly
no test coverage detected