首页 > Web开发 > 详细

httprunner(8)用例调用-RunTestCase

时间:2021-02-09 17:50:39      阅读:20      评论:0      收藏:0      [点我收藏+]

前言

一般我们写接口自动化的时候,遇到复杂的逻辑,都会调用API方法来满足前置条件,Pytest的特性是无法用例之间相互调动的,我们一般只调用自己封装的API方法。
而httprunner支持用例之间的调用,通过RunTestCase对其他测试用例进行调用,并且还可以导出用例中你所需要的变量,来满足后续用例的的运行。
 

RunTestCase

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")
        ),
    ]

 

RunTestCase(name)

用于指定测试步骤名称,该名称将显示在执行日志和测试报告中。

RunTestCase("request with functions")

 

.with_variables

与RunRequest里的用法相同
 

.call

指定你要引用的testcase类名称

.call(RequestWithFunctions)

调用RequestWithFunctions类
 

.export

指定要导出的变量(可以指定多个),后续的测试步骤可以引用导出的变量

.export(*["foo3", "foo4"])

httprunner(8)用例调用-RunTestCase

原文:https://www.cnblogs.com/jiakecong/p/14392910.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!