httprunner call api template

Api to create a login template, the default username and password 800001, the default status code 200 response

name: 登录接口模板
variables:
    expected_status_code: 200
    password: '800001'
    username: '800001'
    vercode: ${gen_random_string(5)}
request:
    url: "/api/login"
    json:
        password: '$password'
        username: '$username'
        vercode: ‘$vercode’
    method: POST
validate:
    - eq: ["status_code", $expected_status_code]

Test passwords and user names matched and unmatched in both cases

-   config:
        base_url: "http://192.168.1.100:8093"
-   test:
        name: 用户名密码正确
        api: api/login.yaml
        validate:
            - eq: ["content.success", True]

-   test:
        name: 用户名存在,密码错误
        api: api/login.yaml
        variables:
            password: '800001'
            username: '800002'
        validate:
            - eq: ["content.success", False]
  -   test:
        name: 密码为空
        api: api/login.yaml
        variables:
            password: ''
            username: '800002'
        validate:
            - eq: ["status_code", 400]
            - eq: ["content.errors.0.defaultMessage", '请输入密码']   ##.0表示列表的第一个字段

-   test:
        name: 用户名为空
        api: api/login.yaml
        variables:
            password: '800002'
            username: ''
        validate:
            - eq: ["status_code", 400]
            - eq: ["content.errors.0.defaultMessage", '请输入用户名']

Guess you like

Origin blog.csdn.net/qq1105273619/article/details/90700942