程序员

HttpRunner的关联方法

2020-05-13  本文已影响0人  xianling_he

抓包工具: Fiddler

找到这个Doc parameter最初出现的请求位置

确定Document是变化以后,需要在yaml文件中添加参数值

使用extract 将document id保存,提供后面请求使用

    extract:
        documentId: content.data.id
name: /api/list/create_doc
    request:
        data:
            folderId: '0'
            type: '0'
        headers:
            Content-Type: application/x-www-form-urlencoded; charset=UTF-8
            Sec-Fetch-Dest: empty
            Sec-Fetch-Mode: cors
            Sec-Fetch-Site: same-origin
            User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
                (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
            X-Requested-With: XMLHttpRequest
        method: POST
        url: https://mubu.com/api/list/create_doc
    extract:
        documentId: content.data.id
    validate:
    -   eq:
        - status_code
        - 200
    -   eq:
        - headers.Content-Type
        - application/json;charset=UTF-8
    -   eq:
        - content.code
        - 0
    -   eq:
        - content.msg
        - null

将使用document id的部分进行替换

代码如下:

-   name: /doc${documentId}
    request:
        headers:
            Sec-Fetch-Dest: document
            Sec-Fetch-Mode: navigate
            Sec-Fetch-Site: same-origin
            Sec-Fetch-User: ?1
            User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
                (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
        method: GET
        url: https://mubu.com/doc${documentId}
    validate:
    -   eq:
        - status_code
        - 200

检查关联的参数是否能够被读取

hrun demo_mubu.yml --log-level debug

在报告中查看关联数据的正确性

image.png createURL.png ReadDoc.png
上一篇 下一篇

猜你喜欢

热点阅读