postman

https://www.getpostman.com/apps  【访问速度比较差】

https://pan.baidu.com/s/15HCd43CJhh3siT338vreIQ

postman中collection folder request的概念,发送请求前后可写的代码,api加密,api访问用户身份鉴别,登陆后token需要传入之后接口使用

postman 非常好用的接口测试工具,可以根据项目模块划分,业务流程,在postman中创建自己的结构,方便测试。

postman中中央mytest是我创建的工作空间,如果是pro版本,可以

分享到team方便团队合作,免费版可以把collections分享到私人空间,方便自己在不同电脑上登录时可以同步获取,

collection可以作为一个项目的api组织,folder是collection的下一级,可以作为一个功能模块,folder下可以创建很多request,一个request就是一个api请求。

image

环境变量

image

全局变量,token是用户登陆后返回的用户请求标识,验证是哪个用户请求。

ar_id 是文章id ,

auth是api加密校验签名 ,

time是api请求所带时间戳

image

文件夹类似功能模块

所用图片都是postman官网所截取

image

上图是请求发送前,到请求,到返回,到返回后执行的test,postman可以接受js编码,并提供了api供我们调用。

在发送请求前pre-request script可以对api进行加密生成签名【常用算法为:对请求所有参数按照字典排序,urlencode,再连接秘钥进行md5生成签名。这时需要设置全局变量auth为空,并在请求参数中携带auth,生成签名时unset掉该参数,生成签名后对全局变量auth进行设置】,请求返回后可以在test script中编写断言【

pm.test(“200ok”, function () {

pm.response.to.have.status(200);

});】或者指定下一个要执行的request【postman.setNextRequest(“获取用户信息”);】。

Scopes can be viewed as different kinds of buckets in which values reside. If a variable is in two different scopes, the scope with a higher priority wins and the variable gets its value from there. Postman resolves scopes using this hierarchy progressing from broad to narrow scope.

If a variable from the currently active environment shares its name with a global variable, the environment variable will take priority. In other words, global variables are overridden by environment variables

这段英文的意思是变量有这几个作用域,范围越小优先级越高,如果global 和 environment中有一个相同名称的变量,则environment会覆盖掉global中的那个变量值

image

需要注意的是这些变量在pre-request script中,{{}}并未被替换成值,所以做加密所有request参数时【api加密签名场景】,

要循环替换掉这些变量模板,否则跟服务端接口验证不通过了。

if(postman.__execution.request.method==“GET”){

var params = postman.__execution.request.url.query;

}else{

var params = postman.__execution.request.body.urlencoded;

}

postman 中创建的api测试,可以进行web查看,可以作为api文档供前端或者手机app开发人员查看。

image

newman是postman的命令行工具,可以把postman中你创建的collection  folder request 和环境变量导出为文件,使用命令行执行。

image

执行run就可以跑项目1下所有api,也可以只跑用户下或者文件模块下,甚至某个request

newman run -h

npm install -g newman

newman run PostmanCollection.json -e environment.json --bail newman

Options:

Utility:

-h, --help                      output usage information

-v, --version                   output the version number

Basic setup:

–folder [folderName]           Specify a single folder to run from a collection.

-e, --environment [file|URL]    Specify a Postman environment as a JSON [file]

-d, --data [file]               Specify a data file to use either json or csv

-g, --globals [file]            Specify a Postman globals file as JSON [file]

-n, --iteration-count [number]  Define the number of iterations to run

Request options:

–delay-request [number]        Specify a delay (in ms) between requests [number]

–timeout-request [number]      Specify a request timeout (in ms) for a request

Misc.:

–bail                          Stops the runner when a test case fails

–silent                        Disable terminal output

–no-color                      Disable colored output

-k, --insecure                  Disable strict ssl

-x, --suppress-exit-code        Continue running tests even after a failure, but exit with code=0

–ignore-redirects              Disable automatic following of 3XX responses

Jenkins 是常用的持续集成工具,可以定时执行你写的脚步,达到定期部署或者手动构建,好处是一键可以构建自己的项目,只要把脚步写好。

有一个流程大家可选【搭建svn服务器或者git,web服务端源码,postman测试用例,手机app ui测试用例都提交到该svn上,Jenkins查看web的svn变化,有则执行postman的api测试用例。Jenkins创建构建手机app的作业,当构建完app,则执行ui测试】

Starting/stopping the service

  • To manually start the daemon:

sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

  • To manually stop the daemon:

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist

Uninstall Jenkins

To uninstall Jenkins service from your Mac OS X computer, execute uninstall script from terminal:

|

‘/Library/Application Support/Jenkins/Uninstall.command’

|

image

jenkins执行shell命令,有时提示Command not found

先在cmd 命令行窗口试试是否可以执行,可以的话,就需要在jenkins shell脚本中第一行加

#!/bin/bash -ilex  以读取/etc/profile和~/.bash_profile等文件

image

#!/bin/bash -ilex

newman run  /Users/xiaobao/Jenkins/项目1.postman_collection.json -e /Users/xiaobao/Jenkins/测试.postman_environment.json

创建好这个Jenkins任务后点击立即构建,构建完可以查看控制台输出

✓  200ok  ✓  less than 400ms  ✓  success ┌─────────────────────────┬──────────┬──────────┐ │                         │ executed │   failed │ ├─────────────────────────┼──────────┼──────────┤ │              iterations │        1 │        0 │ ├─────────────────────────┼──────────┼──────────┤ │                requests │        4 │        0 │ ├─────────────────────────┼──────────┼──────────┤ │            test-scripts │       11 │        0 │ ├─────────────────────────┼──────────┼──────────┤ │      prerequest-scripts │       11 │        0 │ ├─────────────────────────┼──────────┼──────────┤ │              assertions │       12 │        0 │ ├─────────────────────────┴──────────┴──────────┤ │ total run duration: 870ms                     │ ├───────────────────────────────────────────────┤ │ total data received: 1.99KB (approx)          │ ├───────────────────────────────────────────────┤ │ average response time: 105ms                  │ └───────────────────────────────────────────────┘ Finished: SUCCESS

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值