通過RunTestCase對其他測試用例進行調用,並且還可以導出用例中所需要的變量,來滿足后續用例的的運行。
主要的兩個特征:一個是在一個用例中引用另一個測試用例,另一個則是變量的導出與引用
teststeps = [ Step( RunTestCase("request with functions") .with_variables( **{"foo1": "testcase_ref_bar1", "expect_foo1": "testcase_ref_bar1"} ) .call(RequestWithFunctions) .export(*["foo3"]) ), Step( RunRequest("post form data") .with_variables(**{"foo1": "bar1"}) .post("/post") .with_headers( **{ "User-Agent": "HttpRunner/${get_httprunner_version()}", "Content-Type": "application/x-www-form-urlencoded", } ) .with_data("foo1=$foo1&foo2=$foo3") .validate() .assert_equal("status_code", 200) .assert_equal("body.form.foo1", "bar1") .assert_equal("body.form.foo2", "bar21") ),
]
1. RunTestCase(name)
這個參數還是一個名稱,畢竟RunTestCase還是一個Step,這個名稱同樣會在日志和報告中顯示。
2. .with_variables
這個變量跟RunRequest里的用法一樣。
3. .call
這里就是指定要引用的testcase類名稱了。
4. .export
可以指定要導出的變量,以供后續Step引用。
可以看的.export()內部是一個列表[],這里可以用來導出多個變量