具有随机数的API的炮兵脚本不起作用

时间:2018-01-29 13:44:13

标签: load-testing web-api-testing artillery

我在api调用中使用随机数,如下所示,但是给出错误。

"post": {
   "url":  "https://host/abc?Id=1&Amount={{{$randomNumber(4000,40000)}}}&rate={{{$randomNumber(1000000,1200000)}}}&amountType=1"
}

它给出了错误

 { Error: Line 1: Unexpected token }
at createError (C:\Users\chintamanim\AppData\Roaming\npm\node_modules\artillery\node_modules\esprima\esprima.js:2392:21)
at unexpectedTokenError (C:\Users\chintamanim\AppData\Roaming\npm\node_modules\artillery\node_modules\esprima\esprima.js:2467:13)
at throwUnexpectedToken (C:\Users\chintamanim\AppData\Roaming\npm\node_modules\artillery\node_modules\esprima\esprima.js:2472:15)
at parsePrimaryExpression (C:\Users\chintamanim\AppData\Roaming\npm\node_modules\artillery\node_modules\esprima\esprima.js:3266:13)
at inheritCoverGrammar (C:\Users\chintamanim\AppData\Roaming\npm\node_modules\artillery\node_modules\esprima\esprima.js:2648:18)
at parseLeftHandSideExpressionAllowCall (C:\Users\chintamanim\AppData\Roaming\npm\node_modules\artillery\node_modules\esprima\esprima.js:3373:20)
at inheritCoverGrammar (C:\Users\chintamanim\AppData\Roaming\npm\node_modules\artillery\node_modules\esprima\esprima.js:2648:18)
at parsePostfixExpression (C:\Users\chintamanim\AppData\Roaming\npm\node_modules\artillery\node_modules\esprima\esprima.js:3449:16)
at parseUnaryExpression (C:\Users\chintamanim\AppData\Roaming\npm\node_modules\artillery\node_modules\esprima\esprima.js:3509:20)
at inheritCoverGrammar (C:\Users\chintamanim\AppData\Roaming\npm\node_modules\artillery\node_modules\esprima\esprima.js:2648:18)
 index: 29,
 lineNumber: 1,
 column: 30,
 description: 'Unexpected token }' }
 Unexpected error, Artillery shutting down.

1 个答案:

答案 0 :(得分:0)

现在正在工作。 可以这样使用 “ {{$ randomNumber(1,3)}}”或$ randomNumber(1,3)

参考: How to create random string or Number in artillery load testing script?