Get the App
SLTechnology News&Howtos  ›  Servers  › 

Postman built-in script description

Shulou Source: shulou.com Published: 2022-06-03 04:37:15 10月04日 Update

. Built-in script description

1. Clear a global variable Clear a global variable corresponding to the script: postman.clearGlobalVariable ("variable_key"); parameter: key 2 of the variable to be cleared. Clear an environment variable Clear an environment variable corresponding script: postman.clearEnvironmentVariable ("variable_key"); parameter: the key 3.response of the environment variable to be cleared contains the content Response body:Contains string corresponding script: tests ["Body matches string"] = responseBody.has ("string_you_want_to_search"); parameter: expected content 4. Convert xml format response to son format Response body:Convert XML body to a JSON Object corresponding script: var jsonObject = xml2Json (responseBody); Parameter: (default does not need to set parameters, for the response of the interface) the xml 5.response to be converted is equal to the expected content Response body:Is equal to a string corresponding script: tests ["Body is correct"] = responseBody = "response_body_string" Parameters: response 6.json is expected to parse the value of key to verify the Response body:JSON value check corresponding script: tests ["Args key contains argument passed as url parameter"] = 'test' in responseJSON.args parameter: test replaces the tested value, args replaces the tested key 7. Check whether the header information of response has the tested field Response headers:Content-Type header check corresponding script: tests ["Content-Type is present"] = postman.getResponseHeader ("Content-Type"); parameter: expected header 8. Response time judgment Response time is less than 200ms corresponding script: tests ["Response time is less than 200ms"] = responseTime < 200; parameters: response time 9. Set the global variable Set an global variable corresponding to the script: postman.setGlobalVariable ("variable_key", "variable_value"); parameter: global variable key value 10. Set the environment variable Set an environment variable corresponding to the script: postman.setEnvironmentVariable ("variable_key", "variable_value"); parameters: the key value of the environment variable 11. Judge the status code Status code:Code is 200 corresponding to the script: tests ["Status code is 200"] = responseCode.code! = 400; parameters: status code 12. Check whether code name contains content Status code:Code name has string corresponding script: tests ["Status code name has string"] = responseCode.name.has ("Created"); parameter: expected code name contains string 13. The script for a successful post request Status code:Successful POST request: tests ["Successful POST request"] = responseCode.code = 201 | | responseCode.code = = 202; 14. Use Tiny Validator for JSON data corresponds to script: var schema = {"items": {"type": "boolean"}}; var data1 = [true, false]; var data2 = [true, 123]; console.log (tv4.error) Tests ["Valid Data1"] = tv4.validate (data1, schema); tests ["Valid Data2"] = tv4.validate (data2, schema); parameters: you can modify the key-value pairs in items to correspond to the parameters of the verification json

Tags: Scripts parameters variables content environment global time format status check validation tiny success information fields characters strings interfaces validators Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB Shulou Tech Info Linux Shulou Information