{"id":6910,"date":"2023-04-14T09:07:46","date_gmt":"2023-04-14T02:07:46","guid":{"rendered":"https:\/\/www.briswell-vn.com\/?p=6910"},"modified":"2023-04-14T09:07:46","modified_gmt":"2023-04-14T02:07:46","slug":"postman-va-mot-so-tinh-nang-huu-ich","status":"publish","type":"post","link":"https:\/\/www.briswell-vn.com\/en\/news\/postman-va-mot-so-tinh-nang-huu-ich\/","title":{"rendered":"POSTMAN AND USEFUL FEATURES"},"content":{"rendered":"<p><\/p>\n<p style=\"text-align: left\">Since its first release in 2012, POSTMAN has gained over 25 million users for nearly a decade and has become the most popular tool used in API (<strong>Application Programming Interface<\/strong>) testing.<\/p>\n<p>POSTMAN has various features, including the ability to send HTTP requests using methods such as POST, PUT, GET, and DELETE, to check returned data in formats such as JSON and XML, to manage requests using the Collection feature, and to share data with the Import \/ Export feature. It is designed to be user-friendly and can be used by individuals without programming knowledge.<\/p>\n<p>After a long time working with the basic features, you may also want to learn more advanced features of POSTMAN. If so, you should not miss the helpful information shared by Briswell Vietnam in this article.<\/p>\n<h2>1. Install POSTMAN<\/h2>\n<p>As an open-source tool, you can easily download and install it from the following link.<\/p>\n<p>POSTMAN Homepage: <a class=\"waffle-rich-text-link\" href=\"https:\/\/www.postman.com\/downloads\/\">https:\/\/www.POSTMAN.com\/downloads\/<\/a><\/p>\n<h2>2. Useful Features<\/h2>\n<p>In addition to the basic features listed at the beginning of the article, POSTMAN also provides some advanced features as follows.<\/p>\n<h3>2.1 Set Variable<\/h3>\n<h4>2.1.1 Why should we use variables?<\/h4>\n<p>When working on requests within the same project, multiple values are often commonly used and repeatedly declared, such as domain names in URLs and Authorization values.<\/p>\n<p>If the domain name changes or the Authorization value is updated to a new value, it is necessary to update the new value for each request, which can be time-consuming and prone to errors. As an example, during phase 1, the site&#8217;s URL is set to https:\/\/api-example1.com\/. However, in phase 2, the site&#8217;s URL is changed to https:\/\/api-example2.com\/. This would require a considerable amount of time to update the new domain name for all requests.<\/p>\n<p>To solve this problem, POSTMAN provides five types of variables with different ranges, which include Global variables, Collection variables, Environment variables, Data variables and Local variables. By using a variable, when you need to update information such as the domain names in the URLs or Authorization values, simply access the variable&#8217;s declared location and update the new value for the variable to call it. All requests with the current value are automatically updated to the latest value.<\/p>\n<p>This article describes how to declare variables within the scope of a Collection (other variables are declared in the same way). In other words, a variable declared within a Collection is only valid within that Collection and its requests.<\/p>\n<h4>2.1.2 Declare variables in POSTMAN Collection<\/h4>\n<p>Step 1: Click the three dots icon (\u30fb\u30fb\u30fb) to the right of the<strong> Collection<\/strong> name and select<strong> Edit<\/strong>.<br \/>\nStep 2: In the <strong>Edit Collection<\/strong> dropdown menu, select the <strong>Variables<\/strong> tab.<br \/>\nStep 3: In the <strong>VARIABLE<\/strong> column, enter the name of the variable you want to declare.<br \/>\nStep 4: In the <strong>CURRENT VALUE<\/strong> column, assign a value to the variable.<br \/>\nStep 5: Press the <strong>Save<\/strong> button.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7147\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26085721\/Khai-b%C3%A1o-bi%E1%BA%BFn_EN.png\" alt=\"\" width=\"1827\" height=\"685\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26085721\/Khai-b%C3%A1o-bi%E1%BA%BFn_EN.png 1827w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26085721\/Khai-b%C3%A1o-bi%E1%BA%BFn_EN-300x112.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26085721\/Khai-b%C3%A1o-bi%E1%BA%BFn_EN-1024x384.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26085721\/Khai-b%C3%A1o-bi%E1%BA%BFn_EN-768x288.png 768w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26085721\/Khai-b%C3%A1o-bi%E1%BA%BFn_EN-1536x576.png 1536w\" sizes=\"auto, (max-width: 1827px) 100vw, 1827px\" \/><\/p>\n<h4>2.1.3 Call variable in Request<\/h4>\n<p>Step 1: Open the file <strong>Request<\/strong>.<br \/>\nStep 2: Call the variable using the format <span style=\"color: #ff6600\"><code>{{variable_name}}<\/code><\/span><br \/>\nStep 3: Press the <strong>Save<\/strong> button.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7148\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26090348\/G%E1%BB%8Di-bi%E1%BA%BFn_EN.png\" alt=\"\" width=\"1390\" height=\"390\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26090348\/G%E1%BB%8Di-bi%E1%BA%BFn_EN.png 1390w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26090348\/G%E1%BB%8Di-bi%E1%BA%BFn_EN-300x84.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26090348\/G%E1%BB%8Di-bi%E1%BA%BFn_EN-1024x287.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26090348\/G%E1%BB%8Di-bi%E1%BA%BFn_EN-768x215.png 768w\" sizes=\"auto, (max-width: 1390px) 100vw, 1390px\" \/><\/p>\n<h3>2.2 Console window<\/h3>\n<p>Normally, we check the returned value on the <strong>Body<\/strong> tab. However, for requests with a large number of parameters, it can be difficult to see the results in the <strong>Body<\/strong> tab as we need to scroll down many times to check the information below. To solve this problem, we can use the <span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot; Th\u00f4ng th\u01b0\u1eddng, ch\u00fang ta s\u1ebd ki\u1ec3m tra gi\u00e1 tr\u1ecb \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1 \u1edf tab Body. Tuy nhi\u00ean, \u0111\u1ed1i v\u1edbi tr\u01b0\u1eddng h\u1ee3p s\u1ed1 l\u01b0\u1ee3ng parameter tr\u1ea3 v\u1ec1 nhi\u1ec1u th\u00ec vi\u1ec7c xem k\u1ebft qu\u1ea3 \u1edf tab Body c\u00f3 ch\u00fat kh\u00f3 kh\u0103n, ph\u1ea3i thao t\u00e1c l\u0103n chu\u1ed9t nhi\u1ec1u l\u1ea7n \u0111\u1ec3 ki\u1ec3m tra \u0111\u01b0\u1ee3c c\u00e1c th\u00f4ng tin \u1edf ph\u00eda d\u01b0\u1edbi. \u0110\u1ec3 gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1 n\u00e0y, ch\u00fang ta c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh console.log(pm.response.json()) \u0111\u1ec3 in gi\u00e1 tr\u1ecb tr\u1ea3 v\u1ec1 ra c\u1eeda s\u1ed5 Console v\u00e0 ki\u1ec3m tra th\u00f4ng tin tr\u1ea3 v\u1ec1 \u1edf \u0111\u00f3.&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:13057,&quot;3&quot;:{&quot;1&quot;:0},&quot;11&quot;:4,&quot;12&quot;:0,&quot;15&quot;:&quot;Times New Roman&quot;,&quot;16&quot;:12}\"><span style=\"color: #993300\"><code>console.log(pm.response.json())<\/code><\/span> <\/span> statement to print the returned value to the <strong>Console<\/strong> window and check if it&#8217;s there.<\/p>\n<h4>2.2.1 Print the returned value to the Console window using the statement console.log(pm.response.json()).<\/h4>\n<p>Step 1: Click on the <strong>Console<\/strong> icon in the bottom left corner of the screen to open the <strong>Console<\/strong> window.<br \/>\nStep 2: Select the <strong>Tests<\/strong> tab.<br \/>\nStep 3: Write the <span style=\"color: #993300\"><code>console.log(pm.response.json())<\/code> <\/span>statement.<br \/>\nStep 4: Press the <strong>Send<\/strong> button.<br \/>\nStep 5: View the returned information printed in the <strong>Console<\/strong> window.<br \/>\nStep 6: To delete the printed information, click the <strong>Clear<\/strong> button in the right corner of the <strong>Console<\/strong> window.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7149\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26091515\/C%E1%BB%ADa-s%E1%BB%95-Console_EN.png\" alt=\"\" width=\"1862\" height=\"937\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26091515\/C%E1%BB%ADa-s%E1%BB%95-Console_EN.png 1862w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26091515\/C%E1%BB%ADa-s%E1%BB%95-Console_EN-300x151.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26091515\/C%E1%BB%ADa-s%E1%BB%95-Console_EN-1024x515.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26091515\/C%E1%BB%ADa-s%E1%BB%95-Console_EN-768x386.png 768w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26091515\/C%E1%BB%ADa-s%E1%BB%95-Console_EN-1536x773.png 1536w\" sizes=\"auto, (max-width: 1862px) 100vw, 1862px\" \/><\/p>\n<h4>2.2.2 About the statement console.log(pm.response.json()).<\/h4>\n<p>The statement <span style=\"color: #993300\"><code>console.log(pm.response.json())<\/code><\/span> is composed of two components as follows:<br \/>\n\u30fb<span style=\"color: #993300\"><code>console.log()<\/code><\/span>: a function used to print the value of the object being called.<br \/>\n\u30fb<span style=\"color: #000000\"><code>pm.response.json()<\/code><\/span>: a syntax defined by POSTMAN to extract the information returned in the body.<\/p>\n<p><strong>Example 1: The Response Body is an object, and we want to print out all the information returned in the body.<\/strong><br \/>\n\u2192 Let&#8217;s use the statement <code>console.log(pm.response.json())<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7150\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26092620\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-1_EN.png\" alt=\"\" width=\"1335\" height=\"927\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26092620\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-1_EN.png 1335w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26092620\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-1_EN-300x208.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26092620\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-1_EN-1024x711.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26092620\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-1_EN-768x533.png 768w\" sizes=\"auto, (max-width: 1335px) 100vw, 1335px\" \/><\/p>\n<p><strong>Example 2: The Response Body is an array, and we want to print out all the information returned in the body.<\/strong><br \/>\n\u2192 Let&#8217;s use the statement <code>console.log(pm.response.json())<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7151\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26093221\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-2_EN.png\" alt=\"\" width=\"1321\" height=\"740\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26093221\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-2_EN.png 1321w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26093221\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-2_EN-300x168.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26093221\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-2_EN-1024x574.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26093221\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-2_EN-768x430.png 768w\" sizes=\"auto, (max-width: 1321px) 100vw, 1321px\" \/><\/p>\n<p><strong>Example 3: The Response Body is an array, and we want to print only the information of the first object in that array.<\/strong><br \/>\nIn terms of the number and nature of response parameters, the objects in an array are equivalent, so it is only necessary to check the representation of one object.<br \/>\n\u2192 Let&#8217;s use the statement <code>console.log(pm.response.json()[0])<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7152\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26093751\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-3_EN.png\" alt=\"\" width=\"1321\" height=\"925\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26093751\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-3_EN.png 1321w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26093751\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-3_EN-300x210.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26093751\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-3_EN-1024x717.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26093751\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-3_EN-768x538.png 768w\" sizes=\"auto, (max-width: 1321px) 100vw, 1321px\" \/><\/p>\n<p><strong>Example 4: The Response Body is an object, and we want to print the value of a specific response parameter in that object.<\/strong><br \/>\n\u2192 Let&#8217;s use the statement <code>console.log(pm.response.json().{response parameter name})<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7153\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26094459\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-4_EN.png\" alt=\"\" width=\"1442\" height=\"775\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26094459\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-4_EN.png 1442w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26094459\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-4_EN-300x161.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26094459\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-4_EN-1024x550.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26094459\/C%C3%A2u-l%E1%BB%87nh-console.log_V%C3%AD-d%E1%BB%A5-4_EN-768x413.png 768w\" sizes=\"auto, (max-width: 1442px) 100vw, 1442px\" \/><\/p>\n<h3>2.3 Introduce the Script used to test the response parameter<\/h3>\n<p>For Search APIs, it is common to encounter scenarios where there is an extra or missing response parameter returned as compared to the response parameter specified in the API specification. In such cases, we can use the following script to verify if the response parameter returned from the API matches the response parameters specified in the design in object units.<\/p>\n<pre>let expectedKeys = []\r\nlet returnKeys = Object.keys(pm.response.json())\r\nfunction checkReturnKeys(expectedKeys,returnKeys){\r\n    let duplicatedExpectedKeysAray = expectedKeys.filter((item,index) =&gt; {\r\n        return expectedKeys.indexOf(item) !== index})\r\n    if (duplicatedExpectedKeysAray.length === 0) {\r\n        let missExpectedKeys = expectedKeys.filter((item) =&gt; !returnKeys.includes(item))\r\n        let redundantExpectedKeys = returnKeys.filter((item) =&gt; !expectedKeys.includes(item))\r\n        if(!_.isEqual(expectedKeys,returnKeys)){\r\n            if(missExpectedKeys.length !== 0 &amp;&amp; redundantExpectedKeys.length !== 0){\r\n                console.log('Some parameters that are described in the specification are not being returned in the API response result, such as: '+missExpectedKeys+'. Please check again.')\r\n                console.log('Some parameters are being returned in the API response result that are not described in the specification, such as: '+redundantExpectedKeys+'. Please check again.')\r\n            }else if(missExpectedKeys.length !== 0){\r\n                console.log('Some parameters that are described in the specification are not being returned in the API response result, such as: '+missExpectedKeys+'. Please check again.')\r\n            }else{\r\n                console.log('Some parameters are being returned in the API response result that are not described in the specification, such as: '+redundantExpectedKeys+'. Please check again.')\r\n            }\r\n            return false;\r\n        }else{\r\n            console.log('The parameters returned from the API match those described in the specification.')\r\n            return true;\r\n        }\r\n    }else{\r\n        console.log('The expectedKeys array contains elements with duplicate names, such as: '+ duplicatedExpectedKeysAray+'. Please check again.')\r\n    }\r\n}\r\npm.test(\"Check return keys\", () =&gt; {\r\n    pm.expect(checkReturnKeys(expectedKeys.sort(),returnKeys.sort())).eql(true);\r\n});<\/pre>\n<h4>2.3.1 How the above script works?<\/h4>\n<p>\u30fbIn the first line: <span style=\"color: #000000\"><code>let expectedKeys = []<\/code><\/span><br \/>\n\u2192 The <strong>expectedKeys<\/strong> is an array that contains the response parameter name elements extracted from the API specification (<strong>Expected Result<\/strong>).<br \/>\n\u30fbIn the second line: <span style=\"color: #000000\"><code>let returnKeys = Object.keys(pm.response.json())<\/code><\/span><br \/>\n\u2192 The <strong>returnKeys<\/strong> is an array that contains the response parameter name elements returned by executing API (<strong>Actual Result<\/strong>).<br \/>\n\u30fbThe script compares the elements of the <strong>expectedKeys<\/strong> array (<strong>Expected Result<\/strong>) with the <strong>returnKeys<\/strong> array (<strong>Actual Result<\/strong>).<br \/>\n\u2192 If the two arrays match completely, the script returns a <strong><span style=\"color: #008000\">PASS<\/span> <\/strong>result in the <strong>Test Results<\/strong> and a notification message in the <strong>Console<\/strong> tab.<br \/>\n\u2192 If there is no match, the script returns a <strong><span style=\"color: #ff0000\">FAIL<\/span><\/strong> result in the <strong>Test Results<\/strong> tab and a notification message in the<strong> Console <\/strong>tab.<br \/>\nTherefore, the following steps should be done before running the above script:<br \/>\n\u30fbOn the first line, copy and paste the response parameter names extracted from the API specification into the empty brackets <code>[]<\/code> to create the expectedKeys array.<br \/>\n\u30fbOn the second line, modify <code>pm.response.json()<\/code> to retrieve the response parameter names returned by executing the API and creating the returnKeys array.<\/p>\n<h4>2.3.2 Execution steps<\/h4>\n<p><strong>Step 1<\/strong>: Paste the above script into the <strong>Tests<\/strong> tab on POSTMAN.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7156\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26100828\/Script_B%C6%B0%E1%BB%9Bc-1_EN-1.png\" alt=\"\" width=\"1855\" height=\"781\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26100828\/Script_B%C6%B0%E1%BB%9Bc-1_EN-1.png 1855w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26100828\/Script_B%C6%B0%E1%BB%9Bc-1_EN-1-300x126.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26100828\/Script_B%C6%B0%E1%BB%9Bc-1_EN-1-1024x431.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26100828\/Script_B%C6%B0%E1%BB%9Bc-1_EN-1-768x323.png 768w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26100828\/Script_B%C6%B0%E1%BB%9Bc-1_EN-1-1536x647.png 1536w\" sizes=\"auto, (max-width: 1855px) 100vw, 1855px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 2<\/strong>: Open the API specification and extract the names of the response parameters for the object that needs to be tested in the response section.<br \/>\nFor example, the autoDisplaySearchId API has a main object as &#8220;autoDisplay&#8221; and child objects such as &#8220;material&#8221;, &#8220;laminate&#8221;, etc.<br \/>\nThe illustration below is a guide to extracting the response parameter for the main object, which is autoDisplay.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7157\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26101030\/script_B%C6%B0%E1%BB%9Bc-2_EN.png\" alt=\"\" width=\"1818\" height=\"670\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26101030\/script_B%C6%B0%E1%BB%9Bc-2_EN.png 1818w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26101030\/script_B%C6%B0%E1%BB%9Bc-2_EN-300x111.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26101030\/script_B%C6%B0%E1%BB%9Bc-2_EN-1024x377.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26101030\/script_B%C6%B0%E1%BB%9Bc-2_EN-768x283.png 768w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26101030\/script_B%C6%B0%E1%BB%9Bc-2_EN-1536x566.png 1536w\" sizes=\"auto, (max-width: 1818px) 100vw, 1818px\" \/><\/p>\n<p><strong>Step 3<\/strong>: Paste the response parameter name extracted in step 2 into <code>[]<\/code> in the first line of the above script.<br \/>\nExample:<br \/>\nBefore pasting: let expectedKeys = <code>[]<\/code><br \/>\nAfter pasting:<br \/>\nlet expectedKeys = <code>[\"id\",\"type\",\"code\",\"name\",\"width1\",\"width2\",\"paste\",\"unit\",\"laminateType\",<\/code><br \/>\n<code>\"sort\",\"supplier\",\"maker\",\"settingDate\",\"beforeUnit\",\"comment\",\"disableFlag\",\"createdAt\",\"createdBy\",<\/code><br \/>\n<code>\"createdUserName\",\"updatedAt\",\"updatedBy\",\"updatedUserName\"]<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7159\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26101419\/script_B%C6%B0%E1%BB%9Bc-3_EN-1.png\" alt=\"\" width=\"1382\" height=\"773\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26101419\/script_B%C6%B0%E1%BB%9Bc-3_EN-1.png 1382w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26101419\/script_B%C6%B0%E1%BB%9Bc-3_EN-1-300x168.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26101419\/script_B%C6%B0%E1%BB%9Bc-3_EN-1-1024x573.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26101419\/script_B%C6%B0%E1%BB%9Bc-3_EN-1-768x430.png 768w\" sizes=\"auto, (max-width: 1382px) 100vw, 1382px\" \/><\/p>\n<p><strong>Step 4<\/strong>: In the second line of the above script, modify <code>returnKeys = Object.keys(pm.response.json())<\/code> to match the response parameter names returned by the API for the object being tested.<\/p>\n<p><strong>Example 1<\/strong>: The autoDisplaySearchId API returns an object. If the object to be tested is the &#8220;autoDisplay&#8221; object of the autoDisplaySearchId API, modify <code>returnKeys = Object.keys(pm.response.json())<\/code><\/p>\n<p><strong>Example 2<\/strong>: The autoDisplaySearchId API returns an object. If the object to be tested is the &#8220;material&#8221; object of the autoDisplaySearchId API, modify <code>returnKeys = Object.keys(pm.response.json().material)<\/code><\/p>\n<p><strong>Example 3<\/strong>: The autoDisplaySearch API returns an array. If the object to be tested is the &#8220;autoDisplay&#8221; object of the autoDisplaySearch API, modify <code>returnKeys = Object.keys(pm.response.json()[0])<\/code><\/p>\n<p><strong>Example 4<\/strong>: The autoDisplaySearch API returns an array. If the object to be tested is the &#8220;material&#8221; object of the autoDisplaySearch API, modify <code>returnKeys = Object.keys(pm.response.json()[0].material)<\/code><\/p>\n<p>Press the <strong>Send<\/strong> button to send the request and then check the <strong><span style=\"color: #008000\">PASS<\/span> <\/strong>\/ <span style=\"color: #ff0000\"><strong>FAIL<\/strong><\/span> results in the <strong>Test Results<\/strong> tab and confirm the notification message in the <strong>Console<\/strong> tab.<\/p>\n<p><strong>Case 1<\/strong>: If the elements in the <strong>expectedKeys<\/strong> array and the <strong>returnKeys<\/strong> array match, the API returns the correct parameters according to the API specification without any missing or extra parameters.<br \/>\n\u30fbTab Test Results: Display <span style=\"color: #008000\"><strong>PASS<\/strong> <\/span>result.<br \/>\n\u30fbTab Console: Display the following message.<br \/>\n<code><span style=\"color: #993300\">\"The parameters returned from the API match those described in the specification.\"<\/span><\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7169\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26105558\/script_check-result_case1_EN-2.png\" alt=\"\" width=\"1858\" height=\"802\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26105558\/script_check-result_case1_EN-2.png 1858w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26105558\/script_check-result_case1_EN-2-300x129.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26105558\/script_check-result_case1_EN-2-1024x442.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26105558\/script_check-result_case1_EN-2-768x332.png 768w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26105558\/script_check-result_case1_EN-2-1536x663.png 1536w\" sizes=\"auto, (max-width: 1858px) 100vw, 1858px\" \/><\/p>\n<p><strong>Case 2<\/strong>: The <strong>expectedKeys<\/strong> array contains the element with the same name.<br \/>\n\u30fbTab Test Results: Display <strong><span style=\"color: #ff0000\">FAIL<\/span> <\/strong>result.<br \/>\n\u30fbTab Console: Display the following message.<br \/>\n<code><span style=\"color: #993300\">\"The expectedKeys array contains elements with duplicate names, such as: {the same name element}. Please check again.\"<\/span><\/code><br \/>\n\u2192 In this case, we need to check the <strong>expectedKeys<\/strong> array and remove any duplicates. After removing the duplicates, we can run the API again.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7163\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103507\/script_check-result_case2_EN.png\" alt=\"\" width=\"1858\" height=\"811\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103507\/script_check-result_case2_EN.png 1858w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103507\/script_check-result_case2_EN-300x131.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103507\/script_check-result_case2_EN-1024x447.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103507\/script_check-result_case2_EN-768x335.png 768w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103507\/script_check-result_case2_EN-1536x670.png 1536w\" sizes=\"auto, (max-width: 1858px) 100vw, 1858px\" \/><\/p>\n<p><strong>Case 3<\/strong>: The API is returning the extra parameters that are not described in the API specification.<br \/>\n\u30fbTab Test Results: Display <strong><span style=\"color: #ff0000\">FAIL<\/span> <\/strong>result.<br \/>\n\u30fbTab Console: Display the following message.<br \/>\n<code><span style=\"color: #993300\">\"Some parameters are being returned in the API response result that are not described in the specification, such as: {parameter name}. Please check again.\"<\/span><\/code><br \/>\n\u2192 In this case, we need to notify the developer to delete the extra parameters.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7164\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103732\/script_check-result_case3_EN.png\" alt=\"\" width=\"1858\" height=\"805\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103732\/script_check-result_case3_EN.png 1858w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103732\/script_check-result_case3_EN-300x130.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103732\/script_check-result_case3_EN-1024x444.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103732\/script_check-result_case3_EN-768x333.png 768w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103732\/script_check-result_case3_EN-1536x665.png 1536w\" sizes=\"auto, (max-width: 1858px) 100vw, 1858px\" \/><\/p>\n<p><strong>Case 4<\/strong>: Do not return response parameters described in API specification.<br \/>\n\u30fbTab Test Results: Display <strong><span style=\"color: #ff0000\">FAIL<\/span> <\/strong>result.<br \/>\n\u30fbTab Console: Display the following message.<br \/>\n<code><span style=\"color: #993300\">\"Some parameters that are described in the specification are not being returned in the API response result, such as: {parameter name}. Please check again.\"<\/span><\/code><br \/>\n\u2192 In this case, we need to notify the developer to add the missing parameters.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7165\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103746\/script_check-result_case4_EN.png\" alt=\"\" width=\"1862\" height=\"767\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103746\/script_check-result_case4_EN.png 1862w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103746\/script_check-result_case4_EN-300x124.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103746\/script_check-result_case4_EN-1024x422.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103746\/script_check-result_case4_EN-768x316.png 768w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103746\/script_check-result_case4_EN-1536x633.png 1536w\" sizes=\"auto, (max-width: 1862px) 100vw, 1862px\" \/><\/p>\n<p><strong>Case 5<\/strong>: Returns both missing and extra response parameters compared to the API specification.<br \/>\n\u30fbTab Test Results: Display <span style=\"color: #ff0000\"><strong>FAIL<\/strong> <\/span>result.<br \/>\n\u30fbTab Console: Display the following message.<br \/>\n<code><span style=\"color: #993300\">\"Some parameters are being returned in the API response result that are not described in the specification, such as: {parameter name}. Please check again.\"<\/span><\/code><br \/>\n<code><span style=\"color: #993300\">\"Some parameters that are described in the specification are not being returned in the API response result, such as: {parameter name}. Please check again.\"<\/span><\/code><br \/>\n\u2192 In this case, we need to notify the developer to delete the extra parameter and add the missing parameter.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-7166\" src=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103758\/script_check-result_case5_EN.png\" alt=\"\" width=\"1862\" height=\"793\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103758\/script_check-result_case5_EN.png 1862w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103758\/script_check-result_case5_EN-300x128.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103758\/script_check-result_case5_EN-1024x436.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103758\/script_check-result_case5_EN-768x327.png 768w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2023\/03\/26103758\/script_check-result_case5_EN-1536x654.png 1536w\" sizes=\"auto, (max-width: 1862px) 100vw, 1862px\" \/><\/p>\n<h2>3. References<\/h2>\n<p>https:\/\/learning.postman.com\/docs\/sending-requests\/variables\/<\/p>\n<p>https:\/\/giangtester.com\/category\/api-testing\/postman\/<\/p>","protected":false},"excerpt":{"rendered":"<p>Since its first release in 2012, POSTMAN has gained over 25 million users for nearly a decade and has become the most popular tool used in API (Application Programming Interface) testing. POSTMAN has various features, including the ability to send HTTP requests using methods such as POST, PUT, GET, and DELETE, to check returned data in formats such as JSON and XML, to manage requests [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":7363,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[4,71],"tags":[],"class_list":["post-6910","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news","category-it-tec"],"_links":{"self":[{"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/posts\/6910","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/comments?post=6910"}],"version-history":[{"count":0,"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/posts\/6910\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/media\/7363"}],"wp:attachment":[{"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/media?parent=6910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/categories?post=6910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/tags?post=6910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}