mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-16 11:57:36 +08:00
merge main
This commit is contained in:
4
examples/account.csv
Normal file
4
examples/account.csv
Normal file
@@ -0,0 +1,4 @@
|
||||
username,password
|
||||
test1,111111
|
||||
test2,222222
|
||||
test3,333333
|
||||
|
@@ -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"}).
|
||||
|
||||
61
examples/parameters_test.json
Normal file
61
examples/parameters_test.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
40
examples/parameters_test.yaml
Normal file
40
examples/parameters_test.yaml
Normal 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
|
||||
Reference in New Issue
Block a user