testing - 在 Postman 测试中检查响应 header 的值

标签 testing automated-tests postman

我想检查具体响应 header (“位置”)中的值作为 Postman 中的测试结果。 在 Postman 的文档中,我找到了如何检查 header 是否存在的示例

pm.test("Content-Type is present", function () {
   pm.response.to.have.header("Content-Type");
});

但我正在寻找的是类似

pm.test("Location value is correct", function () {
   CODE HERE THAT CHECKS "Location" HEADER EQUALS TO SOMETHING;
});

最佳答案

我终于找到了解决方案:

pm.test("Redirect location is correct", function () {
   pm.response.to.have.header("Location");
   pm.response.to.be.header("Location", "http://example.com/expected-redirect-url");
});

关于testing - 在 Postman 测试中检查响应 header 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49253142/

相关文章:

api - postman :找不到拦截器按钮

在 Phoenix 中测试返回 nil 的虚拟字段

java - 在用于 Selenium 测试的 Maven 项目中使 System.setProperty 平台独立

testing - Microsoft 测试管理器中的自动化测试 "build directory of the test run either does not exist or access permission is required"

javascript - 如何通过数组比较两个元素的文本内容

javascript - 如何在 Postman 中编写全局函数

curl - 要求 postman 提供作品,但不要求cURL提供作品

java - TestNG @Test(invocationCount = 20) 到类,@Test(DataProvider ="someList") 到方法

testing - 如何在 Jmeter 中获取字符串长度和 subtring 用户定义的变量

spring - 为什么在 Spring Boot 中有不同类型的集成测试