在 Postman 测试中使用哪个片段来验证 header 值的一部分
Which snippet to use in Postman test to validate a part of a header value
在 API POST 请求的响应中,位置在 header 中作为键和值从两部分构建返回:URL 路径+唯一编号
我只想在 Postman 测试中验证值的 URL 路径,因为每次新请求后唯一 ID 都会不同。
位置示例 header 响应中的值:
api/v1/users/cbca75db-7d7d-4687-9aa0-c68f4rg46465/customers/EXXXXXXXXX/emailaddresses/5637454148
我只想验证:
api/v1/users/cbca75db-7d7d-4687-9aa0-c68f4rg46465/customers/EXXXXXXXXX/emailaddresses/
到目前为止我有:
pm.response.to.have.header("Location");
pm.response.to.be.header("Location", "api/v1/users/cbca75db-7d7d-4687-9aa0-c68f4rg46465/customers/E000088/emailaddresses");
但这不是 100% 正确
如果您只是想检查 header 是否包含字符串的一部分,您可以使用如下内容:
pm.test("Location Header", () => {
pm.response.to.have.header("Location");
pm.expect(pm.response.headers.get("Location")).to.include("api/v1/users/cbca75db-7d7d-4687-9aa0-c68f4rg46465/customers/EXXXXXXXXX/emailaddresses")
})
我不知道 URL 路径中的 guid
和 id
是否会改变,所以这是非常硬编码的,而不是动态的。
在 API POST 请求的响应中,位置在 header 中作为键和值从两部分构建返回:URL 路径+唯一编号
我只想在 Postman 测试中验证值的 URL 路径,因为每次新请求后唯一 ID 都会不同。
位置示例 header 响应中的值:
api/v1/users/cbca75db-7d7d-4687-9aa0-c68f4rg46465/customers/EXXXXXXXXX/emailaddresses/5637454148
我只想验证:
api/v1/users/cbca75db-7d7d-4687-9aa0-c68f4rg46465/customers/EXXXXXXXXX/emailaddresses/
到目前为止我有:
pm.response.to.have.header("Location");
pm.response.to.be.header("Location", "api/v1/users/cbca75db-7d7d-4687-9aa0-c68f4rg46465/customers/E000088/emailaddresses");
但这不是 100% 正确
如果您只是想检查 header 是否包含字符串的一部分,您可以使用如下内容:
pm.test("Location Header", () => {
pm.response.to.have.header("Location");
pm.expect(pm.response.headers.get("Location")).to.include("api/v1/users/cbca75db-7d7d-4687-9aa0-c68f4rg46465/customers/EXXXXXXXXX/emailaddresses")
})
我不知道 URL 路径中的 guid
和 id
是否会改变,所以这是非常硬编码的,而不是动态的。