用jsonData接收pm返回的response的内容;第二行代码是设置pm的全局变量,set的第一个参数是全局变量的名...
并将其赋给该全局变量,例如:var jsonData = pm.response.json(); pm.globals.set("responseBody",...
tests["hasaccess_token"]=responseBody.has("access_token"); Response body: is equal to string //判断返回内容是否跟预期完全相等。 tests["Bodyiscorrect"]=responseBody==="这里可以改为你的预期内容"; Response body: JSON value check //上文提到,responseBody为字符串类型,支持转为Json格式 varjsonDat...
Clear a global variable (清除全局变量) pm.globals.unset("variable_key"); Get a variable (获取一个变量) 该函数在全局变量和活动环境中搜索变量。 pm.variables.get("variable_key"); Check if response body contains a string (检查响应主体是否包含字符串) pm.test("Body matches string", function (...
postman.setEnvironmentVariable("key", "value"); 2.设置全局变量--Set a global variable postman.setGlobalVariable("key", "value"); 3.检查响应中包含string--Check if response body contains a string tests["Body matches string"] = responseBody.has("string_you_want_to_search"); ...
②、postman.clearGlobalVariable(“variable.key”); 2、Clear an environment variable: ①、清除一个环境变量; ②、postman.clearGlobalEnvironmentVariable(“variable.key”); 3、Response body:Contains string: ①、response包含内容; ②、tests[“Body matches string”]=responseBody.has(“string_you_want_to...
postman.setEnvironmentVariable("key", "value"); 2.设置全局变量--Set a global variable postman.setGlobalVariable("key", "value"); 3.检查响应中包含string--Check if response body contains a string tests["Body matches string"] = responseBody.has("string_you_want_to_search"); ...
parse(responseBody).***; 新版语法: pm.***; response.code; response.status; response.responseTime; response.text(); response.json().***; 四、postman 变量 1、旧版环境变量语法 //设置环境变量 postman.setEnvironmentVariable(variableName, variableValue) //设置全局变量 postman.setGlobalVariable(...
pm.collectionVariables.set("variable_key", "variable_value"); pm.environment.unset("variable_key"); pm.globals.unset("variable_key"); pm.collectionVariables.unset("variable_key"); pm.sendRequest("https://postman-echo.com/get", function (err, response) { ...
var data = JSON.parse(responseBody);tests["program's lenght"] = data.programs.length === 5; 将返回中的值设置为一个环境变量 pm.environment.set("key",xxx.data.value);或者postman.setEnvironmentVariable("key", "value"); 将返回中的值设置为一个全局变量, pm.globals.set("key",xxx.data.val...