POSTMAN assertion method

Below a Log interface interface testing POSTMAN

interface:

{{something_uat1}}/api-homething/loginOutThird

return value:

{
    "code": "200",
    "message": "操作成功",
    "dataMap": true
}

Postman Interface Screenshot:

Postman's test assertions:

Specific TEST METHODS:

Description: red part of the description of the test method; orange region of the original sample Postman test method; assertions black portions below was prepared according to the Log Specific operation of the interface.

// 1. The detection result returned body contains fields the Response: A String the Contains
/ *
pm.test ( "Body The matches String", function () {
    pm.expect (pm.response.text ()) to.include (. " string_you_want_to_search ");
});

* /
Pm.test ( "return results include the detection field", function () {
    . Pm.expect (pm.response.text ()) to.include ( "successful operation");
});

// 2. Get the value of environment variable: pm.variables.get ( "variable_key");
var = pm.environment.get Data ( "something_uat1");
Tests [ 'environment variable detection setting value'] = data == = "http://shomething.uat1.rs.com";

/ . / 3 contains the test results returned code: 200 is
/ *
pm.test ( "IS 200 is the Status code", function () {
    pm.response.to.have.status (200 is);
});
* /

pm.test ( "IS 200 is the Status code", function () {
    pm.response.to.have.status (200 is);
});

// length below a predetermined 4. Test Response
/ *
pm.test ( "IS less Within last 200ms the Response Time", function () {
    pm.expect (pm.response.responseTime) .to.be.below (200 is);
} );
* /

pm.test ( "IS less Within last 200ms the Response Time", function () {
    pm.expect (pm.response.responseTime) .to.be.below (200 is);
});
// 5. The return detected the resulting string 
/*pm.test("Body iS correct ", function () {
    pm.response.to.have.body (" response_body_string ");
}); * /

pm.test (" detect the return block of text equality ", function () {
    pm.response.to.have.body ( '{" code ":" 200 is "," Message ":" successful operation "," Datamap ": to true}');
});
/ / 6. detect the return expected field values are equal.Here there are three body writing the Response: JSON value the Check
/ *
pm.test ( "Your name Test", function () {
    var jsonData pm.response.json = ();
    pm.expect (jsonData.value) .to.eql (100);
});
* /

//. 1) methods .postman string into json objects
pm.test ( "test the value returned message", function () {
    var jsonData pm.response.json = ();
    pm.expect (jsonData.message) .to.eql ( "successful operation");
});
//2).JSON syntax string into json objects
pm.test ( "test the value returned dataMap", function () {
    var jsonData the JSON.parse = (the responseBody) ;
    jsonData.dataMap === to true;
});
//. 3) using the method tests to assert
var = jsonData the JSON.parse (the responseBody);
tests [ "test return code = 200"] = jsondata.code === "200";
// 7. return code containing any of the elements
/ *
pm.test("Successful POST request", function () {
    pm.expect(pm.response.code).to.be.oneOf([201,202]);
});*/

pm.test("返回code包含任意元素", function () {
    pm.expect(pm.response.code).to.be.oneOf([200,202]);
});

8 // check JSON document format for the Validator JSON Data Tiny the Use
/ * = {var Schema
  "items": {
    "type": "Boolean"
  }
};

was data1 = [true, false];
was 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;
});      */

// Note: string, boolean type in the type to be lowercase and quotes 

//解释说明,下方定义一个schema描述JSON文档格式
var schema = {
    "properties":{
        "code": {
        "type": "string",
         "description":"return code"
                 },
        "message":{
        "type": "string",
        "description":"return message"
                },
        "dataMap": {
        "type": "boolean",
        "description":"return if it  is successful"
                }
        },
    "required": ["code", "message", "dataMap"]
};

// Get the data interface returned in JSON format

var data=JSON.parse(responseBody);

// responseBody and check whether the definition of the schema is returned matches
pm.test ( 'Valid the Schema IS', function () {
  pm.expect (tv4.validate (Data, schema)) to.be.true;.
 
});

 

 

Published 99 original articles · won praise 43 · views 160 000 +

Guess you like

Origin blog.csdn.net/mayanyun2013/article/details/88697748