前提在chrome 网上应用商店安装postman 和 Postman Interceptor.如下图使用postman的时候最后开启postman Interceptor,如下图然后启动postman工具开始使用。其中{{url}}的使用是因为在设置了环境变量如下图使用{{address}}是因为设置了全局变量如下图Testing 实例来看一些Postman用于test的例子。这些例子中的大多数在Postman中是有效的他们像一行JavaScript语句一样简答。在你的request中你可以有很多的test。注意test脚本在从服务器收到response后执行1.设置环境变量postman.setEnvironmentVariable(key, value);2.设置全局变量postman.setGlobalVariable(key, value);3.检查response的body中是否包含字符串tests[Body matches string] responseBody.has(string_you_want_to_search);4.把XML的body转换成JSON对象var jsonObject xml2Json(responseBody);5.检查response的body是都为一个字符串tests[Body is correct] responseBody response_body_string;6.检查JSON的值var data JSON.parse(responseBody); tests[Your test name] data.value 100;7.内容类型存在检查不区分大小写tests[Content-Type is present] postman.getResponseHeader(Content-Type); //Note: the getResponseHeader() method returns the header value, if it exists.8.内容类型存在区分大小写tests[Content-Type is present] responseHeaders.hasOwnProperty(Content-Type);9.response的响应时间小于200mstests[Response time is less than 200ms] responseTime 200;10.状态码为200tests[Status code is 200] responseCode.code 200;11.Code name contains a stringtests[Status code name has string] responseCode.name.has(Created);12.成功的POST request状态码tests[Successful POST request] responseCode.code 201 || responseCode.code 202;最后下方这份完整的软件测试 视频教程已经整理上传完成需要的朋友们可以自行领取【保证100%免费】软件测试面试文档我们学习必然是为了找到高薪的工作下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料并且有字节大佬给出了权威的解答刷完这一套面试资料相信大家都能找到满意的工作。
使用postman 测试restful接口
前提在chrome 网上应用商店安装postman 和 Postman Interceptor.如下图使用postman的时候最后开启postman Interceptor,如下图然后启动postman工具开始使用。其中{{url}}的使用是因为在设置了环境变量如下图使用{{address}}是因为设置了全局变量如下图Testing 实例来看一些Postman用于test的例子。这些例子中的大多数在Postman中是有效的他们像一行JavaScript语句一样简答。在你的request中你可以有很多的test。注意test脚本在从服务器收到response后执行1.设置环境变量postman.setEnvironmentVariable(key, value);2.设置全局变量postman.setGlobalVariable(key, value);3.检查response的body中是否包含字符串tests[Body matches string] responseBody.has(string_you_want_to_search);4.把XML的body转换成JSON对象var jsonObject xml2Json(responseBody);5.检查response的body是都为一个字符串tests[Body is correct] responseBody response_body_string;6.检查JSON的值var data JSON.parse(responseBody); tests[Your test name] data.value 100;7.内容类型存在检查不区分大小写tests[Content-Type is present] postman.getResponseHeader(Content-Type); //Note: the getResponseHeader() method returns the header value, if it exists.8.内容类型存在区分大小写tests[Content-Type is present] responseHeaders.hasOwnProperty(Content-Type);9.response的响应时间小于200mstests[Response time is less than 200ms] responseTime 200;10.状态码为200tests[Status code is 200] responseCode.code 200;11.Code name contains a stringtests[Status code name has string] responseCode.name.has(Created);12.成功的POST request状态码tests[Successful POST request] responseCode.code 201 || responseCode.code 202;最后下方这份完整的软件测试 视频教程已经整理上传完成需要的朋友们可以自行领取【保证100%免费】软件测试面试文档我们学习必然是为了找到高薪的工作下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料并且有字节大佬给出了权威的解答刷完这一套面试资料相信大家都能找到满意的工作。