当前位置:网站首页>Postman assertion

Postman assertion

2022-06-24 20:47:00 m0_ sixty-two million four hundred and ninety-six thousand nine

A complete interface test , Include : request -> Get the response body -> Assertion   You can see postman How to add assertions

  This ” Tests” That's where we need to deal with assertions ,postman Help us prepare all the functions used for assertions

First set up an assertion scenario , Take the assertion scenario as an example Postman How assertions are used

1. Judge HTTP Returns the status code as 200

2. Determine whether the response body contains :"statusCode":200

3. Parse the response body , And decide statusCode The value of is 200,message The value of is ” Success”

stay SNIPPETS in , Pull down , There is one ” Status code:Code is 200”, This is for the second 1 I'm ready for , Judge HTTP Returns whether the status code is 200. Click on this , You can see it on the left , Assertion code is added automatically

  This means that The name is ” Status code is 200” In the assertion of , Judge responseCode Object's code Property value (HTTP Status code ) Is it 200

Also in SNIPPETS in , Find one ” Response body:Contains string”, This is for the second 2 I'm ready for , Determine the fields in the response body , After clicking , Generate the following code

We need to modify what we want to find in the response message

tests["Body matches string"] = responseBody.has('"statusCode":200'), Determine whether the response body contains :"statusCode":200

  We need to parse JSON Yes , stay SNIPPETS Find ” Response body:JSON value check” And click the , Assertion code is added automatically

jsonData Variables are actually parsed JSON After the object , stay JS in , One JSON Object gets the value of its property , It's direct jsonData.value, therefore , Let's modify the code

tests["response statusCode"] = jsonData.statusCode === 200; // Judge statusCode The value of is 200

tests["response message"] = jsonData.message === 'Success'; // Judge message The value of is ” Success”

原网站

版权声明
本文为[m0_ sixty-two million four hundred and ninety-six thousand nine]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211325596746.html