v3 test example: support session variables

This commit is contained in:
debugtalk
2020-04-20 12:49:53 +08:00
parent 3051a60731
commit 39b8f74b27
3 changed files with 12 additions and 7 deletions

View File

@@ -1,5 +1,7 @@
config: config:
name: "request methods testcase with variables" name: "request methods testcase with variables"
variables:
foo1: session_bar1
base_url: "https://postman-echo.com" base_url: "https://postman-echo.com"
verify: False verify: False
@@ -19,7 +21,7 @@ teststeps:
User-Agent: HttpRunner/3.0 User-Agent: HttpRunner/3.0
validate: validate:
- eq: ["status_code", 200] - eq: ["status_code", 200]
- eq: ["body.args.foo1", "bar1"] - eq: ["body.args.foo1", "session_bar1"]
- eq: ["body.args.foo2", "bar2"] - eq: ["body.args.foo2", "bar2"]
- -
name: post raw text name: post raw text
@@ -34,7 +36,7 @@ teststeps:
data: "This is expected to be sent back as part of response body: $foo1." data: "This is expected to be sent back as part of response body: $foo1."
validate: validate:
- eq: ["status_code", 200] - eq: ["status_code", 200]
- eq: ["body.data", "This is expected to be sent back as part of response body: hello world."] - eq: ["body.data", "This is expected to be sent back as part of response body: session_bar1."]
- -
name: post form data name: post form data
variables: variables:
@@ -49,5 +51,5 @@ teststeps:
data: "foo1=$foo1&foo2=$foo2" data: "foo1=$foo1&foo2=$foo2"
validate: validate:
- eq: ["status_code", 200] - eq: ["status_code", 200]
- eq: ["body.form.foo1", "bar1"] - eq: ["body.form.foo1", "session_bar1"]
- eq: ["body.form.foo2", "bar2"] - eq: ["body.form.foo2", "bar2"]

View File

@@ -5,6 +5,9 @@ from httprunner.v3.schema import TestsConfig, TestStep
class TestCaseRequestMethodsWithVariables(TestCaseRunner): class TestCaseRequestMethodsWithVariables(TestCaseRunner):
config = TestsConfig(**{ config = TestsConfig(**{
"name": "request methods testcase with variables", "name": "request methods testcase with variables",
"variables": {
"foo1": "session_bar1"
},
"base_url": "https://postman-echo.com", "base_url": "https://postman-echo.com",
"verify": False "verify": False
}) })
@@ -29,7 +32,7 @@ class TestCaseRequestMethodsWithVariables(TestCaseRunner):
}, },
"validate": [ "validate": [
{"eq": ["status_code", 200]}, {"eq": ["status_code", 200]},
{"eq": ["body.args.foo1", "bar1"]}, {"eq": ["body.args.foo1", "session_bar1"]},
{"eq": ["body.args.foo2", "bar2"]} {"eq": ["body.args.foo2", "bar2"]}
] ]
}), }),
@@ -49,13 +52,13 @@ class TestCaseRequestMethodsWithVariables(TestCaseRunner):
}, },
"validate": [ "validate": [
{"eq": ["status_code", 200]}, {"eq": ["status_code", 200]},
{"eq": ["body.data", "This is expected to be sent back as part of response body: hello world."]}, {"eq": ["body.data", "This is expected to be sent back as part of response body: session_bar1."]},
] ]
}), }),
TestStep(**{ TestStep(**{
"name": "post form data", "name": "post form data",
"variables": { "variables": {
"foo1": "bar1", "foo1": "session_bar1",
"foo2": "bar2" "foo2": "bar2"
}, },
"request": { "request": {
@@ -69,7 +72,7 @@ class TestCaseRequestMethodsWithVariables(TestCaseRunner):
}, },
"validate": [ "validate": [
{"eq": ["status_code", 200]}, {"eq": ["status_code", 200]},
{"eq": ["body.form.foo1", "bar1"]}, {"eq": ["body.form.foo1", "session_bar1"]},
{"eq": ["body.form.foo2", "bar2"]} {"eq": ["body.form.foo2", "bar2"]}
] ]
}) })