zoukankan      html  css  js  c++  java
  • httprunner(8)用例调用-RunTestCase

    前言

    一般我们写接口自动化的时候,遇到复杂的逻辑,都会调用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"])
    
  • 相关阅读:
    Spring(一)Spring的基本应用
    flask摘记
    python摘记
    String Algorithm
    leetcode -- hard part
    leetcode -- medium part
    leetcodo--Easy part
    unix网络编程
    SQL
    计算机网络知识
  • 原文地址:https://www.cnblogs.com/jiakecong/p/14392910.html
Copyright © 2011-2022 走看看