1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
pm.test('返回结果没有错误', function() { pm.response.to.not.be.error; pm.response.to.have.jsonBody(''); pm.response.to.not.have.jsonBody('error'); });
pm.test('返回结果没有错', function() { pm.response.to.be.ok; pm.response.to.be.withBody; pm.response.to.be.json; });
pm.test('Status code is 200', function() { pm.response.to.have.status(200); });
pm.test('Status code name has string', function() { pm.response.to.have.status('Created'); });
pm.test('Successful POST request', function() { pm.expect(pm.response.code).to.be.oneOf([201, 202]); });
pm.expect(pm.response.headers.get('Content-Type')).to.eql('application/json'); pm.test('Content-Type header is present', function() { pm.response.to.have.header('Content-Type'); });
pm.expect(pm.cookies.has('JSESSIONID')).to.be.true; pm.expect(pm.cookies.get('isLoggedIn')).to.eql('1');
pm.test('Response time is less than 200ms', function() { pm.expect(pm.response.responseTime).to.be.below(200); });
const jsonData = pm.response.json(); pm.expect(jsonData.name).to.eql("Jane");
pm.expect(jsonData.name).to.eql(pm.environment.get("name"));
pm.test('Body matches string', function() { pm.expect(pm.response.text()).to.include('string_you_want_to_search'); });
pm.test('Body is correct', function() { pm.response.to.have.body('response_body_string'); });
pm.test('Your test name', function() { var jsonData = pm.response.json(); pm.expect(jsonData.value).to.eql(100); });
pm.expect(jsonData).to.be.an("object"); pm.expect(jsonData.name).to.be.a("string"); pm.expect(jsonData.age).to.be.a("number"); pm.expect(jsonData.hobbies).to.be.an("array"); pm.expect(jsonData.website).to.be.undefined; pm.expect(jsonData.email).to.be.null;
pm.expect(jsonData.errors).to.be.empty; pm.expect(jsonData.errors).to.be.an('array').that.is.empty; pm.expect(jsonData.areas).to.include("goods"); const contactSettings = jsonData.settings.find(m => m.type === "contact"); pm.expect(contactSettings).to.be.an("object", "找不到联系方式配置信息"); pm.expect(contactSettings.detail).to.have.members(["email", "sms"]);
pm.expect({a: 1, b: 2}).to.have.all.keys('a', 'b'); pm.expect({a: 1, b: 2}).to.have.any.keys('a', 'b'); pm.expect({a: 1, b: 2}).to.not.have.any.keys('c', 'd'); pm.expect({a: 1}).to.have.property('a'); pm.expect({a: 1, b: 2}).to.be.an('object').that.has.all.keys('a', 'b'); pm.expect({a: 1, b: 2}).to.deep.include({a:1});
pm.expect({"a": 1, "b": 123}.a).to.be.oneOf([1, 123]);
pm.expect('').to.be.empty;
|