mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
add unit test and closes #971
This commit is contained in:
@@ -55,3 +55,24 @@ teststeps:
|
||||
- eq: ["body.form.foo1", "testcase_config_bar1"]
|
||||
- eq: ["body.form.foo2", "bar23"]
|
||||
- eq: ["body.form.foo3", "bar21"]
|
||||
|
||||
-
|
||||
name: post form data using json
|
||||
variables:
|
||||
foo2: bar23
|
||||
jsondata:
|
||||
foo1: $foo1
|
||||
foo2: $foo2
|
||||
foo3: $foo3
|
||||
request:
|
||||
method: POST
|
||||
url: /post
|
||||
headers:
|
||||
User-Agent: HttpRunner/3.0
|
||||
Content-Type: "application/json"
|
||||
json: $jsondata
|
||||
validate:
|
||||
- eq: ["status_code", 200]
|
||||
- eq: ["body.data.foo1", "testcase_config_bar1"]
|
||||
- eq: ["body.data.foo2", "bar23"]
|
||||
- eq: ["body.data.foo3", "bar21"]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# NOTE: Generated By HttpRunner v3.1.3
|
||||
# FROM: request_methods/request_with_variables.yml
|
||||
# FROM: request_methods\request_with_variables.yml
|
||||
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
@@ -62,6 +62,25 @@ class TestCaseRequestWithVariables(HttpRunner):
|
||||
.assert_equal("body.form.foo2", "bar23")
|
||||
.assert_equal("body.form.foo3", "bar21")
|
||||
),
|
||||
Step(
|
||||
RunRequest("post form data using json")
|
||||
.with_variables(
|
||||
**{
|
||||
"foo2": "bar23",
|
||||
"jsondata": {"foo1": "$foo1", "foo2": "$foo2", "foo3": "$foo3"},
|
||||
}
|
||||
)
|
||||
.post("/post")
|
||||
.with_headers(
|
||||
**{"User-Agent": "HttpRunner/3.0", "Content-Type": "application/json"}
|
||||
)
|
||||
.with_json("$jsondata")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_equal("body.data.foo1", "testcase_config_bar1")
|
||||
.assert_equal("body.data.foo2", "bar23")
|
||||
.assert_equal("body.data.foo3", "bar21")
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user