mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
v3 feat: support teststep variables
This commit is contained in:
53
examples/postman_echo/request_methods/with_variables.yml
Normal file
53
examples/postman_echo/request_methods/with_variables.yml
Normal file
@@ -0,0 +1,53 @@
|
||||
config:
|
||||
name: "request methods testcase with variables"
|
||||
base_url: "https://postman-echo.com"
|
||||
verify: False
|
||||
|
||||
teststeps:
|
||||
-
|
||||
name: get with params
|
||||
variables:
|
||||
foo1: bar1
|
||||
foo2: bar2
|
||||
request:
|
||||
method: GET
|
||||
url: /get
|
||||
params:
|
||||
foo1: $foo1
|
||||
foo2: $foo2
|
||||
headers:
|
||||
User-Agent: HttpRunner/3.0
|
||||
validate:
|
||||
- eq: ["status_code", 200]
|
||||
- eq: ["body.args.foo1", "bar1"]
|
||||
- eq: ["body.args.foo2", "bar2"]
|
||||
-
|
||||
name: post raw text
|
||||
variables:
|
||||
foo1: "hello world"
|
||||
request:
|
||||
method: POST
|
||||
url: /post
|
||||
headers:
|
||||
User-Agent: HttpRunner/3.0
|
||||
Content-Type: "text/plain"
|
||||
data: "This is expected to be sent back as part of response body: $foo1."
|
||||
validate:
|
||||
- eq: ["status_code", 200]
|
||||
- eq: ["body.data", "This is expected to be sent back as part of response body: hello world."]
|
||||
-
|
||||
name: post form data
|
||||
variables:
|
||||
foo1: bar1
|
||||
foo2: bar2
|
||||
request:
|
||||
method: POST
|
||||
url: /post
|
||||
headers:
|
||||
User-Agent: HttpRunner/3.0
|
||||
Content-Type: "application/x-www-form-urlencoded"
|
||||
data: "foo1=$foo1&foo2=$foo2"
|
||||
validate:
|
||||
- eq: ["status_code", 200]
|
||||
- eq: ["body.form.foo1", "bar1"]
|
||||
- eq: ["body.form.foo2", "bar2"]
|
||||
80
examples/postman_echo/request_methods/with_variables_test.py
Normal file
80
examples/postman_echo/request_methods/with_variables_test.py
Normal file
@@ -0,0 +1,80 @@
|
||||
from httprunner.v3.runner import TestCaseRunner
|
||||
from httprunner.v3.schema import TestsConfig, TestStep
|
||||
|
||||
|
||||
class TestCaseRequestMethodsWithVariables(TestCaseRunner):
|
||||
config = TestsConfig(**{
|
||||
"name": "request methods testcase with variables",
|
||||
"base_url": "https://postman-echo.com",
|
||||
"verify": False
|
||||
})
|
||||
|
||||
teststeps = [
|
||||
TestStep(**{
|
||||
"name": "get with params",
|
||||
"variables": {
|
||||
"foo1": "bar1",
|
||||
"foo2": "bar2"
|
||||
},
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "/get",
|
||||
"params": {
|
||||
"foo1": "$foo1",
|
||||
"foo2": "$foo2"
|
||||
},
|
||||
"headers": {
|
||||
"User-Agent": "HttpRunner/3.0"
|
||||
}
|
||||
},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.args.foo1", "bar1"]},
|
||||
{"eq": ["body.args.foo2", "bar2"]}
|
||||
]
|
||||
}),
|
||||
TestStep(**{
|
||||
"name": "post raw text",
|
||||
"variables": {
|
||||
"foo1": "hello world"
|
||||
},
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "/post",
|
||||
"data": "This is expected to be sent back as part of response body: $foo1.",
|
||||
"headers": {
|
||||
"User-Agent": "HttpRunner/3.0",
|
||||
"Content-Type": "text/plain"
|
||||
}
|
||||
},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.data", "This is expected to be sent back as part of response body: hello world."]},
|
||||
]
|
||||
}),
|
||||
TestStep(**{
|
||||
"name": "post form data",
|
||||
"variables": {
|
||||
"foo1": "bar1",
|
||||
"foo2": "bar2"
|
||||
},
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "/post",
|
||||
"data": "foo1=$foo1&foo2=$foo2",
|
||||
"headers": {
|
||||
"User-Agent": "HttpRunner/3.0",
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
}
|
||||
},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.form.foo1", "bar1"]},
|
||||
{"eq": ["body.form.foo2", "bar2"]}
|
||||
]
|
||||
})
|
||||
]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
TestCaseRequestMethodsWithVariables().run()
|
||||
Reference in New Issue
Block a user