美文网首页
记一下一些用于Postman的Js脚本

记一下一些用于Postman的Js脚本

作者: Super7 | 来源:发表于2017-04-01 16:31 被阅读0次

Pre-request Script

随机获取数组里面的几个值中的一个

var string = "10,20,25,50,75,100";
var array = string.split(",");  //字符串转换成数组
var value = array[Math.round(Math.random()*(array.length-1))];
postman.setEnvironmentVariable("size", value);

随机整数

postman.setEnvironmentVariable("pageNumber", parseInt(Math.random()*1));

unix时间戳

postman.setEnvironmentVariable('timestamp',Math.round(new Date().getTime()/1000) );

Tests断言

tests["HttpStatus code is 200"] = responseCode.code === 200;
tests["Response time is less than 300ms"] = responseTime < 300;

var jsonData = JSON.parse(responseBody);
tests["response statusCode"] = jsonData.code === 200;
tests["response message"] = jsonData.status === "SUCCESS";

相关文章

  • 记一下一些用于Postman的Js脚本

    Pre-request Script 随机获取数组里面的几个值中的一个 随机整数 unix时间戳 Tests断言

  • 【接口测试】8 Postman pre-requests的使用

    一、postman强大的脚本功能 Postman包含一个基于Node.js的强大功能,可以让您在发出请前后添加动态...

  • Postman Script用法

    介绍 Postman提供了一定的脚本编写功能,用户可以通过编写脚本添加一些动态行为,官方介绍如下: Postman...

  • Postman中文文档——脚本简介

    Postman脚本 Postman包含一个基于Node.js的强大的运行库,它允许您向请求和集合添加动态行为。这允...

  • Postman 脚本编程

    Postman 使用 Javascript 编写测试脚本,它运行在 Node.js 之上,因此也继承了 Node....

  • postman测试结果生成测试报告

    背景 在postman完成自动化接口测试脚本的编写,并且测试脚本正确的情况下,为了执行脚本能够生成测试报告用于分析...

  • js 动态加载

    js 脚本懒加载,类似于webpack import()方法,可以适用于静态js文件的加载 脚本文件 使用方式,封...

  • postman 断言

    【Tests】例子 在发送请求并从服务器收到响应后运行测试脚本。 让我们看一下Postman-Tests模块的一些...

  • 什么是JS

    JS是一种运行于JS解析器中的脚本语言。 JS与HTML的关系 HTML是脚本语言,用于浏览器实现对话。 JS的历...

  • Influxdb-nodejs连接Influxdb

    schema.js index.js 使用postman添加数据 使用postman查询数据

网友评论

      本文标题:记一下一些用于Postman的Js脚本

      本文链接:https://www.haomeiwen.com/subject/wwgiottx.html