在postman插件的应用与实战(一)中,介绍了postman插件的安装,使用,collestion的创建以及应用,本小节中,我们来介绍postman结合newman和jenkins持续构建工具,来对postman中的接口测试进行统一的管理。
关于newman的信息,可以到https://www.getpostman.com/docs/newman_intro看详细的信息,这里只介绍newman工具的安装,首先安装node.js,然后执行如下的命令安装newman,命令为:
npm install -g newman --registry=https://registry.npm.taobao.org
安装成功后,在windows命令提示符输入newman,出现如下的截图,表示安装成功,见截图:
见newman工具的常用的命令:
Options:
Utility:
-h, --help output usage information
-V, --version output the version number
Basic setup:
-c, --collection [file] Specify a Postman collection as a JSON [file]
-u, --url [url] Specify a Postman collection as a [url]
-f, --folder [folderName] Specify a single folder to run from a collection. To be used with -c or -u.
-e, --environment [file] Specify a Postman environment as a JSON [file]
-d, --data [file] Specify a data file to use either json or csv
-g, --global [file] Specify a Postman globals file as JSON [file]
-n, --number [number] Define the number of iterations to run
-i, --import [file] Import a Postman backup file, and save collections, environments, and globals. [file]
-p, --pretty (Use with -i) Enable pretty-print while saving imported collections, environments, and globals
Request options:
-y, --delay [number] Specify a delay (in ms) between requests [number]
-r, --requestTimeout [number] Specify a request timeout (in ms) for a request
Misc.:
-s, --stopOnError Stops the runner when a test case fails
-j, --noSummary Doesn't show the summary for each iteration
-C, --noColor Disable colored output
-k, --insecure Disable strict ssl
-l, --tls Use TLSv1
-x, --exitCode Continue running tests even after a failure, but exit with code=1
Output:
-o, --outputFile [file] Path to file where output should be written. [file]
-t, --testReportFile [file] Path to file where results should be written as JUnit XML [file]
-H, --html Export a HTML report to a specified file [file]
在这里,我们在postman插件中创建一个对百度的请求,然后使用newman工具来测试这样的一个过程,见创建的请求百度的collestion截图:
点击百度中的collection的share collection,会出现如下的截图,见截图:
在如上的截图中,点击Download,把文件的内容复制到baidu.json并保存到
C盘下,见baidu.json的内容:
下来使用newman执行该get请求的测试用例,见执行的命令:
cd c:/
newman -c baidu.json
见命令的截图以及执行的结果结果:
我们可以在jenkins创建一个过程,把newman和jenkin结合起来,直接让jenkins工具去执行,而不需要每次使用命令去执行了,见创建的过程的截图:
事实上,创建这样一个过程是很简单的,postman工具唯一的缺点,就是如果需要断言,我们就得支付一定的金额,但是即使不能断言,在实际的测试过程和工作过程中,它依然是比较受欢迎的一个测试接口的测试工具。下一节开始,我们开始学习python中其他请求http库的学习。