httprunner调用api模板

创建登录api模板,用户名密码默认800001,状态响应码默认200

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]

测试密码和用户名匹配和不匹配两种情况

-   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", '请输入用户名']

猜你喜欢

转载自blog.csdn.net/qq1105273619/article/details/90700942