E03_HttpRunner断言:比较器的名称

E03_HttpRunner断言:比较器的名称

E03_HttpRunner断言:比较器的名称_第1张图片

 

在 HttpRunner 中,将断言使用的比较器进行了名称的统一,每个比较器的名称可以有多种别名,如 equals 可以简写成 eq 、 == 或者 is 等名称。 象 eq、ge、gt 等写法,和 Linux 中的 shell 脚本比较符名称相同,可以进行类比记忆。

 

各比较器的名称整理如下:

E03_HttpRunner断言:比较器的名称_第2张图片

 

 

具体的名称列表可以参考源码

\httprunner-2.5.5\httprunner\parser.py

def get_uniform_comparator(comparator):
    """ convert comparator alias to uniform name
    """
    if comparator in ["eq", "equals", "==", "is"]:
        return "equals"
    elif comparator in ["lt", "less_than"]:
        return "less_than"
    elif comparator in ["le", "less_than_or_equals"]:
        return "less_than_or_equals"
    elif comparator in ["gt", "greater_than"]:
        return "greater_than"
    elif comparator in ["ge", "greater_than_or_equals"]:
        return "greater_than_or_equals"
    elif comparator in ["ne", "not_equals"]:
        return "not_equals"
    elif comparator in ["str_eq", "string_equals"]:
        return "string_equals"
    elif comparator in ["len_eq", "length_equals", "count_eq"]:
        return "length_equals"
    elif comparator in ["len_gt", "count_gt", "length_greater_than", "count_greater_than"]:
        return "length_greater_than"
    elif comparator in ["len_ge", "count_ge", "length_greater_than_or_equals",
                        "count_greater_than_or_equals"]:
        return "length_greater_than_or_equals"
    elif comparator in ["len_lt", "count_lt", "length_less_than", "count_less_than"]:
        return "length_less_than"
    elif comparator in ["len_le", "count_le", "length_less_than_or_equals",
                        "count_less_than_or_equals"]:
        return "length_less_than_or_equals"
    else:
        return comparator

 

 

以访问百度首页为例,断言相等,比较词可以有四种等价写法:

- config:
    name: TestCase

- test:
    name: TestStep - 1
    request: 
      url: https://www.baidu.com/
      method: GET
      headers:
        User-Agent: 'ozilla/5.0 (Windows NT 6.1; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0'

    validate:
        # 断言: 是否相等, 以下四种方法是等价的
        - eq: [status_code, 200]

        - is: [status_code, 200]

        - ==: [status_code, 200]

        - equals: [status_code, 200]

 

 

执行以上用例,查看测试报告,四个断言的显示完全相同。

E03_HttpRunner断言:比较器的名称_第3张图片

 

 

 

 

 

 

你可能感兴趣的:(接口自动化测试之,-,HttpRunner框架,软件测试,接口,软件框架)