Jenkins+Postman持续集成搭建及使用

window上使用Jenkins

一、安装nodejs

1.安装postman需要先安装nodejs 下载地址: http://nodejs.cn/download/
   下载后一路next ,安装后,打开cmd,输入node -v ,看到输出node的版本信息,即代表安装成功,环境变量设置也正确。
这里写图片描述

二、安装newman

cmd输入 npm install newman –global
安装完成后,输入指令 newman -v 查看版本,检测是否安装成功,这里注意,newman的包被安装在了npm工具的包下
这里写图片描述
如上图,即安装正确,接下来安装html报告
    npm install -g newman-reporter-html
资料:https://github.com/postmanlabs/newman-reporter-html#readme

三、安装Postman

Postman功能(https://www.getpostman.com/features
   主要用于模拟网络请求包
   快速创建请求
   回放、管理请求
   快速设置网络代理
postman 下载地址:https://www.getpostman.com
安装后,导出Collection
在postman中执行测试用例通过后,将postman中的用例导出,并用Newman执行,如下:

这里写图片描述

Newman 执行脚本

命令行运行collection
cmd进入到collection的json文件的目录下,输入指令
newman run postmanEcho.postman_collection.json

例子1,通过newman 运行postman导出的test1.json文件,并生成多种测试报告(json,junit的xml,html):

newman run c:\test1.json –reporters cli,html,json,junit –reporter-json-export jsonOut.json –reporter-junit-export xmlOut.xml –reporter-html-export htmlOut.html

例子2,运行https://www.getpostman.com/collections/cb0cea0af1467c8008fb(postman生成的 )中的所有api,并使用env.json作为环境变量和globals.json作为全局变量,并使用外部data.csv作为外部数据,最后设置了接口请求超时时间为5S 。

newman run https://www.getpostman.com/collections/cb0cea0af1467c8008fb
–environment env.json –iteration-data data.csv –globals globals.json –timeout-request 5000

例子3
newman run C:\11\testpm.postman_collection.json –reporter-html-export C:\11\htmlOut.html -n 10
迭代10次

Newman语法

1、运行一个集合

newman run 集合名
newman run url地址

2、-e,–environment 指定环境文件路径或者url
  -e的用法是如果我们的集合设置到环境变量,那么但是运行集合文件是报错的,需要使用-e指定才能运行集合,比如运行测试搜索集合

newman run d:\test.postman_collection.json -e d:\test.postman_environment.json

3、-g,–globals 指定全局变量的文件地址或url 用法如-e

4、-d,—-iteration-data 指定用于迭代的数据源文件路径

newman run d:\test.postman_collection.json -e d:\test.postman_environment.json -d d:\testdata.csv

5、-n,–iteration-count 指定迭代次数

newman run 集合名 -n 10(迭代次数)
6、–folder 运行集合中指定的文件夹
  如集合下存在文件(前端接口),使用该命名,则只运行集合中前端接口文件下的接口

7、–export-environment 导出该运行集合中的环境变量文件 可指定路径和名称

newman run d:\test.postman_collection.json -e d:\test.postman_environment.json -d d:\testdata.csv —-export-environment d:\test

–export -environment d:\test 导入环境变量文件名称为test 存储在d盘下
注意:

将该文件导入postman之后还是与导出前的文件名相同,比如此处【test.postman_environment.json】导出前对应的环境变量为【test】,那么test导入之后的命名还是【test】,同样,导出集合也是如此。
8、–export-globals 导出全局环境变量

9、–export-collection 导出集合文件

10、–timeout (ms) 设置整个集合运行完成执行的时间

11、–timeport-request (ms) 指定等待请求返回响应的时间

12、–timeout-script (ms)指定等待脚本执行完成的时间

结合Jenkins

作用:
    1.持续、自动地构建/测试软件项目。
    2.监控一些定时执行的任务。

Jenkins下载地址 https://jenkins.io/download/
步骤一:在Jenkins 机器上安装Newman
步骤二:搭建Jenkins环境,并新建个自由风格的Job
步骤三:进入http://localhost:8080
步骤四:构建选择Execute Windows batch command,并输入newman 运行命令
这里写图片描述
这里写图片描述
这里写图片描述

点击完成后,在点击立即构建

备注:
可能在执行的时候 出现 newman指令非内部或外部指令
解决方法:
这里写图片描述
这里写图片描述

点击新增,添加nodejs、npm环境变量

这里写图片描述

  • 3
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值