postman动态设置参数

目的:处理集合入参不便于动态更新参数
要通过 Postman 的 Pre-request Script 方法动态设置集合中 isVipArticle 字段的值

// 动态计算或获取 isVipArticle 的值
const dynamicIsVipArticleValue = true; // 这里可以是动态计算的值或从某个 API 中获取的值

// 设置环境变量
pm.environment.set("isVipArticle", dynamicIsVipArticleValue);

数据模板

{
    "list": [
        {
            "articleId": "139296248",
            "title": "自动化测试遇到内存溢出问题解决",
            "postTime": "2024-05-29 15:03:58",
            "viewCount": "204",
            "commentCount": "0",
            "commentAuth": "2",
            "isTop": "0",
            "status": "1",
            "username": "weixin_50752621",
            "type": "1",
            "isNeedFans": "0",
            "isNeedVip": "0",
            "isVipArticle": "{{isVipArticle}}",
            "editorType": 1,
            "isRecommend": false,
            "totalExposures": 21,
            "fansCount": 0,
            "diggCount": 1,
            "collectCount": 0,
            "coverImage": [
                "https://img-blog.csdnimg.cn/img_convert/55f7c19d42dd4ed98ed1f132a0f82787.png"
            ],
            "voteId": 0,
            "isLock": false,
            "deprecated": false,
            "isShowFeedback": false,
            "complaintArticleId": 0,
            "complaintTitle": null,
            "complaintUrl": null,
            "complaintArticleStatus": null,
            "isComplaint": null,
            "complaintStatus": null,
            "complaintOrderNumber": null,
            "scheduledTime": 0,
            "downloadShareDataUrl": "https://blog.csdn.net/phoenix/web/v1/share/download-share-data?articleId=139296248",
            "plan": null,
            "qualityScore": 32,
            "qualitySpecification": "https://blog.csdn.net/u010280923/article/details/131449478"
        }
    ]
}

你可能感兴趣的:(postman,lua,测试工具)