2.6 随机数配置

一、在自动化脚本中,会对很多入参进行参数化配置

有的参数使用随机值,有的参数可能需要使用给定列表中的某一个值

新建一个js,exports各种随机值


const Mock = require('mockjs');
const moment = require('moment');
exports.randomKey = Mock.mock({'number|0-1': 1}).number;
exports.randomName = Mock.mock({
    'array|1': [
        '测试0',
        '测试1',
        '测试2'
    ]
}).array;
exports.randomUrl = Mock.mock({
    'array|1': [
        'http://www.baidu.com',
        'http://www.csdn.net',
        'http://www.taobao.com'
    ]
}).array;
exports.randomUnit = Mock.mock({
    'array|1': [
        'DAY',
        'HOUR',
    ]
}).array;
exports.randomNum = Mock.mock({'number|1-7': 7}).number;
exports.randomDate = moment().format('YYYY-MM-DD HH:mm:ss');
exports.randomTriggerWay = Mock.mock({
    'array|1': [
        'AUTO',
        'MANUAL',
    ]
}).array;

在case中进行引用

/**
 * parmsData新建接口传参
 * editData为编辑接口传参
 * @type {{randomKey?: *, randomName?: *, randomUrl?: *, randomUnit?: *, randomNum?: *, randomDate?: *|string}}
 */
const randomParms = require('../parmlist/taskrandom');
exports.parmsData = [
    {
        testName: 'AutoTest1',
        testDesc: '自动化运行',
        name: `${randomParms.randomName}`,
        isFile: 0,
        isImg: `${randomParms.randomKey}`,
    },
    {
        testName: 'AutoTest4',
        testDesc: '自动化运行',
        startUrl: `${randomParms.randomUrl}`,
        effectiveDate: `${randomParms.randomDate}`,
        isFile: `${randomParms.randomKey}`,
        isImg: `${randomParms.randomKey}`,
        
    }
]

exports.editData = [
    {
        testName: 'EditAutoTest',
        testDesc: '编辑自动化运行',
        effectiveDate: `${randomParms.randomDate}`,
        isImg: `${randomParms.randomKey}`,
        isFile: `${randomParms.randomKey}`,
    },

]

exports.task = [
    {requestName: 'get', res: [{code: '0000'}, {msg: '一切ok'}, {totalCount: 1}]},
    {requestName: 'edit', res: [{code: '0000'}, {msg: '一切ok'}, {data: '修改任务完成'}]},
    {requestName: 'delete', res: [{code: '0000'}, {msg: '一切ok'}]},
    {requestName: 'save', res: [{code: '0000'}, {msg: '一切ok'}]},
    {requestName: 'reset', res: [{code: '0000'}, {msg: '一切ok'}]}
]

 

上一篇:light4j一个轻量级的低延时、高吞吐量、内存占用量小的API平台


下一篇:Delphi7下SuperObject的JSON使用方法