From 39b8f74b2745d4cdbd47a2bc01494d1f43015dd2 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 20 Apr 2020 12:49:53 +0800 Subject: [PATCH] v3 test example: support session variables --- .../postman_echo/request_methods/with_functions.yml | 0 .../postman_echo/request_methods/with_variables.yml | 8 +++++--- .../request_methods/with_variables_test.py | 11 +++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) delete mode 100644 examples/postman_echo/request_methods/with_functions.yml diff --git a/examples/postman_echo/request_methods/with_functions.yml b/examples/postman_echo/request_methods/with_functions.yml deleted file mode 100644 index e69de29b..00000000 diff --git a/examples/postman_echo/request_methods/with_variables.yml b/examples/postman_echo/request_methods/with_variables.yml index 050d7910..008dd007 100644 --- a/examples/postman_echo/request_methods/with_variables.yml +++ b/examples/postman_echo/request_methods/with_variables.yml @@ -1,5 +1,7 @@ config: name: "request methods testcase with variables" + variables: + foo1: session_bar1 base_url: "https://postman-echo.com" verify: False @@ -19,7 +21,7 @@ teststeps: User-Agent: HttpRunner/3.0 validate: - eq: ["status_code", 200] - - eq: ["body.args.foo1", "bar1"] + - eq: ["body.args.foo1", "session_bar1"] - eq: ["body.args.foo2", "bar2"] - name: post raw text @@ -34,7 +36,7 @@ teststeps: 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."] + - eq: ["body.data", "This is expected to be sent back as part of response body: session_bar1."] - name: post form data variables: @@ -49,5 +51,5 @@ teststeps: data: "foo1=$foo1&foo2=$foo2" validate: - eq: ["status_code", 200] - - eq: ["body.form.foo1", "bar1"] + - eq: ["body.form.foo1", "session_bar1"] - eq: ["body.form.foo2", "bar2"] diff --git a/examples/postman_echo/request_methods/with_variables_test.py b/examples/postman_echo/request_methods/with_variables_test.py index cdec850e..c68c99fa 100644 --- a/examples/postman_echo/request_methods/with_variables_test.py +++ b/examples/postman_echo/request_methods/with_variables_test.py @@ -5,6 +5,9 @@ from httprunner.v3.schema import TestsConfig, TestStep class TestCaseRequestMethodsWithVariables(TestCaseRunner): config = TestsConfig(**{ "name": "request methods testcase with variables", + "variables": { + "foo1": "session_bar1" + }, "base_url": "https://postman-echo.com", "verify": False }) @@ -29,7 +32,7 @@ class TestCaseRequestMethodsWithVariables(TestCaseRunner): }, "validate": [ {"eq": ["status_code", 200]}, - {"eq": ["body.args.foo1", "bar1"]}, + {"eq": ["body.args.foo1", "session_bar1"]}, {"eq": ["body.args.foo2", "bar2"]} ] }), @@ -49,13 +52,13 @@ class TestCaseRequestMethodsWithVariables(TestCaseRunner): }, "validate": [ {"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(**{ "name": "post form data", "variables": { - "foo1": "bar1", + "foo1": "session_bar1", "foo2": "bar2" }, "request": { @@ -69,7 +72,7 @@ class TestCaseRequestMethodsWithVariables(TestCaseRunner): }, "validate": [ {"eq": ["status_code", 200]}, - {"eq": ["body.form.foo1", "bar1"]}, + {"eq": ["body.form.foo1", "session_bar1"]}, {"eq": ["body.form.foo2", "bar2"]} ] })