Newman + Jenkins implement the interface automated testing

First, what Newman

Newman Newman is the classic brand mobile phone, ha ha, just kidding. . . Do not take it seriously, simply put Newman is the command-line version of the Postman, see the official website address .

Newman can use Postman exported collection files directly from the command line to run, to run the operation of the Postman interface instead of the command line, if not Postman test automation interfaces, can refer to how to do test automation interfaces Postman

Because it is a command line operation, it can be done with the interface jenkins automated testing.

Second, how to install

npm install -g newman

mac can also be installed with the brew

brew install newman

Third, how to use

1. Run a local file

newman run examples/sample-collection.json

Running style is this

2. Run the file online

collection files can also be an online address

newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv

Style runs as follows
conv_ops

3. Run with node.js library

const newman = require('newman'); // require newman in your project
 
// call newman.run to pass `options` object and wait for callback
newman.run({
    collection: require('./sample-collection.json'),
    reporters: 'cli'
}, function (err) {
    if (err) { throw err; }
    console.log('collection run complete!');
});

4. Export Report

-R --reporters or may be used to specify the type of output, supported types are cli, json, html, junit, progress and emojitrain
default specified CLI, if you want to specify a plurality can be used in the following manner

newman run examples/sample-collection.json -r cli,json,html

The output to the command line, and export a json and html reports, as follows

html open like this

json like this

Fourth, the command-line interface to the real test

Next, we tested the 32 interfaces

1. Export the file collection

I have a file called local export colection课货.postman_collection.json

2. Export environment variables file

Because I rely interface dependent environment variable {{kehuo}}, also need to export the environment variables, generates a file called my locallocal.postman_environment

3. Perform the test

newman run -e ./local.postman_environment.json -r cli,html ./课货.postman_collection.json

说明:-e指定了环境变量文件,-r指定输出格式,这里我指定了命令行直接输出,和生成html,最后跟的就是我们collection文件啦

执行结果如下

html文件打开如下

五、Newman+Jenkins实现自动化测试

1.jenkins机器安装newman

npm install -g newman

2.将postman文件上传到git仓库

如下,我添加了一个autotesting文件夹,分别放了接口文件postman_collection.json和环境变量文件postman_environment.json

3.jenkins新建项目

这一步选择吴亦凡的freestyle,你看这个面又长又宽,就像这个碗又大又圆~

4.jenkins项目指定git地址和分支

5.jenkins项目newman脚本

6.执行构建

7.查看结果

可以看到,我们的脚本已经重新了,再往后看,有3个接口测试失败了,还给出了原因

就是这么简单,惊不惊喜,意不意外,yeah buddy ! light weight baby !

Guess you like

Origin www.cnblogs.com/chenqionghe/p/12417263.html