zoukankan      html  css  js  c++  java
  • 【HttpRunner v3.x】笔记—7. 测试用例-teststeps-RunTestCase

    以前我在写接口自动化用例的时候,为了保证用例的独立性,需要在setUp里调用各种满足用例的一些前置条件,其中就不乏调用了其他测试用例中的方法。

    而httprunner也是支持了这一项很重要的特性,通过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")
            ),
    

    1. RunTestCase(name)

    这个参数呢还是一个名称,毕竟RunTestCase还是一个Step,这个名称同样会在日志和报告中显示。

    2. .with_variables

    这个变量跟RunRequest里的用法一样。

    3. .call

    这里就是指定你要引用的testcase类名称了。

    4. .export

    可以指定要导出的变量,以供后续Step引用。
    可以看的.export()内部是一个列表[],这里可以用来导出多个变量。

  • 相关阅读:
    redis是什么?
    mysql用户权限设置
    大白话说Java反射:入门、使用、原理 (转)
    iptables只允许指定ip访问本机的指定端口
    CSS系列——前端进阶之路:初涉Less
    MySQL分页查询优化
    linux 面试题
    CSS中定义CLASS时,中间有空格和没空格的区别是什么?
    MySQL Explain详解
    EBS 系统当前完成请求时间监测
  • 原文地址:https://www.cnblogs.com/pingguo-softwaretesting/p/13215007.html
Copyright © 2011-2022 走看看