merge main

This commit is contained in:
debugtalk
2022-01-06 11:17:12 +08:00
27 changed files with 1248 additions and 731 deletions

4
examples/account.csv Normal file
View File

@@ -0,0 +1,4 @@
username,password
test1,111111
test2,222222
test3,333333
1 username password
2 test1 111111
3 test2 222222
4 test3 333333

View File

@@ -19,14 +19,18 @@ func TestCaseCallFunction(t *testing.T) {
TestSteps: []hrp.IStep{
hrp.NewStep("get with params").
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)}", "foo3": "Foo3"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
Extract().
WithJmesPath("body.args.foo1", "varFoo1").
Validate().
AssertEqual("status_code", 200, "check status code").
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").
AssertTypeMatch("body.args.foo3", "str", "check args foo3 is type string").
AssertStringEqual("body.args.foo3", "foo3", "check args foo3 case-insensitivity").
AssertContains("body.args.foo3", "Foo", "check contains ").
AssertContainedBy("body.args.foo3", "this is Foo3 test", "check contained by"), // notice: request params value will be converted to string
hrp.NewStep("post json data with functions").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).

View File

@@ -0,0 +1,61 @@
{
"config": {
"name": "request methods testcase: validate with parameters",
"parameters": {
"user_agent": [
"iOS/10.1",
"iOS/10.2"
],
"username-password": "${parameterize(examples/account.csv)}"
},
"parameters_setting": {
"strategy": {
"user_agent": "sequential",
"username-password": "random"
},
"iteration": 6
},
"variables": {
"app_version": "v1",
"user_agent": "iOS/10.3"
},
"base_url": "https://postman-echo.com",
"verify": false
},
"teststeps": [
{
"name": "get with params",
"variables": {
"foo1": "$username",
"foo2": "$password",
"foo3": "$user_agent"
},
"request": {
"method": "GET",
"url": "/get",
"params": {
"foo1": "$foo1",
"foo2": "$foo2",
"foo3": "$foo3"
},
"headers": {
"User-Agent": "$user_agent,$app_version"
}
},
"validate": [
{
"check": "status_code",
"assert": "equals",
"expect": 200,
"msg": "check status code"
},
{
"check": "body.args.foo3",
"assert": "not_equal",
"expect": "iOS/10.3",
"msg": "check app version"
}
]
}
]
}

View File

@@ -0,0 +1,40 @@
config:
name: "request methods testcase: validate with parameters"
parameters:
user_agent: [ "iOS/10.1", "iOS/10.2" ]
username-password: ${parameterize(examples/account.csv)}
parameters_setting:
strategy:
user_agent: "sequential"
username-password: "random"
iteration: 6
variables:
app_version: v1
user_agent: iOS/10.3
base_url: "https://postman-echo.com"
verify: False
teststeps:
- name: get with params
variables:
foo1: $username
foo2: $password
foo3: $user_agent
request:
method: GET
url: /get
params:
foo1: $foo1
foo2: $foo2
foo3: $foo3
headers:
User-Agent: $user_agent,$app_version
validate:
- check: status_code
assert: equals
expect: 200
msg: check status code
- check: body.args.foo3
assert: not_equal
expect: iOS/10.3
msg: check app version