httprunner—validate校验

httprunner的response.py源码中定义了校验规则

eq:等于

ne:不等于

def get_uniform_comparator(comparator: Text):
    """ convert comparator alias to uniform name
    """
    if comparator in ["eq", "equals", "equal"]:
        return "equal"
    elif comparator in ["lt", "less_than"]:
        return "less_than"
    elif comparator in ["le", "less_or_equals"]:
        return "less_or_equals"
    elif comparator in ["gt", "greater_than"]:
        return "greater_than"
    elif comparator in ["ge", "greater_or_equals"]:
        return "greater_or_equals"
    elif comparator in ["ne", "not_equal"]:
        return "not_equal"
    elif comparator in ["str_eq", "string_equals"]:
        return "string_equals"
    elif comparator in ["len_eq", "length_equal"]:
        return "length_equal"
    elif comparator in [
        "len_gt",
        "length_greater_than",
    ]:
        return "length_greater_than"
    elif comparator in [
        "len_ge",
        "length_greater_or_equals",
    ]:
        return "length_greater_or_equals"
    elif comparator in ["len_lt", "length_less_than"]:
        return "length_less_than"
    elif comparator in [
        "len_le",
        "length_less_or_equals",
    ]:
        return "length_less_or_equals"
    else:
        return comparator

实例:

base_url: ${ENV(HOME_BASE_URL)}
name: taskList
request:
  headers:
    x-rp-token: ${ENV(LOGIN_TOKEN)}
  json: $query
  method: POST
  url: /api/workbench/channel/task/taskList
  verify: false
validate:
- eq:
  - status_code
  - 200
- ne:
  - content.errormsg
  - 系统错误

HttpRunner,从零到熟练运用,个人实战总结请见:https://www.yuque.com/zaygee/httprunner

你可能感兴趣的:(HttpRunner)