about
Primer official website saying:
Postman是一个API开发的协作平台。Postman的特性简化了构建API的每一步并简化了协作,因此您可以更快地创建更好的API。
download
Net official download link: https://www.getpostman.com/downloads/
Baidu cloud link: https://pan.baidu.com/s/1YSafbmRWxB3YcKHxlF03pA extraction code: k44l
installation
Installation is straight all the way to the next step on OK.
use
Affirmation
postman assertion is written in JavaScript, you can write in the designated area postman client.
clear a global variable | Clear the global variable | pm.globals.unset("variable_key"); |
---|---|---|
Clear an environment variable | Clear an environment variable | pm.environment.unset("variable_key"); |
get a global variable | Get a global variable | pm.globals.get("variable_key"); |
get a variable | Get a variable | pm.variables.get("variable_key"); |
Get an environment variable | Get an environment variable | pm.environment.get("variable_key"); |
response body:contains string | Check response body contains the string | pm.test("Body matches string", function () { pm.expect(pm.response.text()).to.include("string_you_want_to_search"); }); |
response body:convert XML body to a JSON object | response body: Convert XML to JSON objects | var jsonObject = xml2Json(responseBody); |
response body:is equal to a string | A string member is equal to check response | pm.test("Body is correct", function () { pm.response.to.have.body("response_body_string"); }); |
response body:JSON value check | Check the value of a field in the response body JSON | pm.test("Your test name", function () { var jsonData = pm.response.json(); pm.expect(jsonData.value).to.eql(100); }); |
response headers:content-Type header check | Check the content-Type header is included in the return | pm.test("Content-Type is present", function () { pm.response.to.have.header("Content-Type"); }); |
response time is than 200ms | Response time exceeds 200ms | pm.test("Response time is less than 200ms", function () { pm.expect(pm.response.responseTime).to.be.below(200); }); |
send s request | Sends a request | pm.sendRequest("https://postman-echo.com/get", function (err, response) { console.log(resp onse.json()); }); |
set a global variable | Setting a global variable | pm.globals.set("variable_key", "variable_value"); |
set an environment variable | Set an environment variable | pm.environment.set("variable_key", "variable_value"); |
status code:Code is 200 | Status code: Code 200 | pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); |
status code:code name has string | Status code: code designated character string | pm.test("Status code name has string", function () { pm.response.to.have.status("Created"); }); |
status code:successful POST request | Status codes: Successful post requests | pm.test("Successful POST request", function () { pm.expect(pm.response.code).to.be.oneOf([201,202]); }); |
use tiny validator for JSON data | Use tiny verifier data as json | var schema = { "items": { "type": "boolean" } }; var data1 = [true, false]; var data2 = [true, 123]; pm.test('Schema is valid', function() { pm.expect(tv4.validate(data1, schema)).to.be.true; pm.expect(tv4.validate(data2, schema)).to.be.true; }); |