美文网首页
apipost使用mock随机获取多组数据中的一组数据进行测试

apipost使用mock随机获取多组数据中的一组数据进行测试

作者: 木卯小台 | 来源:发表于2021-03-29 14:31 被阅读0次

登录接口测试的时候,会有个登录账号每个账号都需要测试一下,为了不每测试一个账号就修改一下body参数,可以在预执行脚本中编写一个mock脚本进行获取

把这些登录账号设置为数组,在获取数组,把数组中的值赋值为环境变量或者全局变量,调用变量就可以了。

var arr = [{“test”:[“xiaoya”,“1”]},{“test”:[“admin”,“2”]},{“test”:[“xiaoming”,“3”]}];

var index = Math.floor((Math.random()*arr.length));

var test=arr[index];

apt.globals.set(“username”, test.test[0]);

apt.globals.set(“password”, test.test[1]);

相关文章

网友评论

      本文标题:apipost使用mock随机获取多组数据中的一组数据进行测试

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