Postman + newman + jenkins 的API自动化测试应用

Posted nancy05

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Postman + newman + jenkins 的API自动化测试应用相关的知识,希望对你有一定的参考价值。

一、环境配置

 

Postman

postman 的具体使用可以参考另外一篇文章:postman 做接口测试之学习笔记

Newman

第一步,安装nodejs。 
第二步,在nodejs命令行安装newman,即命令行输入如下命令:

npm install -g newman

jenkins

去官网(https://jenkins.io/index.html)下载jenkins

 

二、Postman + Newman + jenkins 的使用

 

1. 在postman中导出testcase 文件夹(即存各个接口的collection文件夹)和设置的环境变量文件。

如下所示,导出来的是个json 格式的文件

 

 

 

2. jenkins配置

注意:如果是安装在本地的Jenkins,要将jenkins开启,切换到jenkins.war 的路径下, 执行 java -jar jenkins.war 则可以开启了。

在jenkins上配置如下图,这个路径就是上面通过postman导出文件的路径。 

 

剩下的就是jenkins的常规操作了,比如设置好邮箱后点击立即构建或者设置多久构建一次,这样自动化就跑起来了,等待自动化测试结束后我们就可以收到测试成功或者失败的测试报告邮件了(依赖于设置)。

通过上面这些步骤即可完成基于postman和Jenkins的自动化接口测试。

 

Newman的使用:

可以参考:

Newman - Running collections in the command line

newman 官方文档

newman github

 

Usage: newman [options]

  Options:

    -h, --help                      output usage information
    -V, --version                   output the version number
    -c, --collection [file]         Specify a Postman collection as a JSON [file]
    -u, --url [url]                 Specify a Postman collection as a [url]
    -f, --folder [folder-name]      Run a single folder from a collection. To be used with -c or -u
    -e, --environment [file]        Specify a Postman environment as a JSON [file]
    --environment-url [url]         Specify a Postman environment as a URL
    -E, --exportEnvironment [file]  Specify an output file to dump the Postman environment before exiting [file]
    -d, --data [file]               Specify a data file to use either json or csv
    -g, --global [file]             Specify a Postman globals file [file]
    -G, --exportGlobals [file]      Specify an output file to dump Globals before exiting [file]
    -y, --delay [number]            Specify a delay (in ms) between requests
    -r, --requestTimeout [number]   Specify a request timeout (in ms) for requests (Defaults to 15000 if not set)
    -R, --avoidRedirects            Prevents Newman from automatically following redirects
    -s, --stopOnError               Stops the runner with code=1 when a test case fails
    -j, --noSummary                 Doesn\'t show the summary for each iteration
    -n, --number [number]           Define the number of iterations to run
    -C, --noColor                   Disable colored output
    -S, --noTestSymbols             Disable symbols in test output and use PASS|FAIL instead
    -k, --insecure                  Disable strict ssl
    -l, --tls                       Use TLSv1
    -N, --encoding [encoding-type]  Specify an encoding for the response. Supported values are ascii,utf8,utf16le,ucs2,base64,binary,hex
    -x, --exitCode                  Continue running tests even after a failure, but exit with code=1. Incompatible with --stopOnError
    -o, --outputFile [file]         Path to file where output should be written [file]
    -O, --outputFileVerbose [file]  Path to file where full request and responses should be logged [file]
    -t, --testReportFile [file]     Path to file where results should be written as JUnit XML [file]
    -i, --import [file]             Import a Postman backup file, and save collections, environments, and globals [file] (Incompatible with any option except pretty)
    -p, --pretty                    Enable pretty-print while saving imported collections, environments, and globals
    -H, --html [file]               Export a HTML report to a specified file [file]
    -W, --whiteScreen               Black text for white screen
    -L, --recurseLimit [limit]      Do not run recursive resolution more than [limit] times. Default = 10. Using 0 will prevent any variable resolution

  Newman is a command-line collection runner for Postman. You must specify a collection file or a collection URL to run newman

  A collection file or URL is mandatory
  Examples:

    newman -c POSTMAN_COLLECTION
    newman -u POSTMAN_COLLECTION -e POSTMAN_ENVIRONMENT
    newman -c POSTMAN_COLLECTION -f SAMPLE_FOLDER

  For more documentation, issues and examples head over to https://github.com/postmanlabs/newman

 

以上是关于Postman + newman + jenkins 的API自动化测试应用的主要内容,如果未能解决你的问题,请参考以下文章

postman+newman+jenkins环境部署

Jenkins+postman+Newman之API自动化测试

Postman+Newman+jenkins实现API自动化测试

Postman+Newman+Jenkins接口自动化框架

postman+newman+node.js+git+jenkins实现接口自动化持续集成

postman+newman+jenkins接口集成测试