{"id":1932,"date":"2022-06-17T06:02:44","date_gmt":"2022-06-17T06:02:44","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2022\/06\/17\/clone-of-api-basics-and-architecture\/"},"modified":"2022-12-21T19:34:19","modified_gmt":"2022-12-21T19:34:19","slug":"perform-validations-and-execute-tests-in-a-workflow","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2022\/06\/17\/perform-validations-and-execute-tests-in-a-workflow\/","title":{"rendered":"Perform validations and execute tests in a workflow"},"content":{"rendered":"<h3 id=\"t-1655640850441\"><b>Perform validations and execute tests in a workflow<\/b><\/h3>\n<p>Welcome you all to the brand new \u2018API Testing\u2019 blog series! In the previous blog, we had studied how to execute POST requests in Postman. We also studied how to chain GET and POST requests. In this tutorial, we will learn how to perform some validations. We will also learn how to execute all the tests in a single workflow!! So let us begin!!!&nbsp;<\/p>\n<h3 id=\"t-1655640850442\"><b><b>1. What you will Learn in this blog?<\/b><\/b><\/h3>\n<ul>\n<li>Perform \u2018status code 200\u2019 validation<\/li>\n<li>Perform string validation<\/li>\n<li>Execute all the tests in a collection as a single workflow<\/li>\n<\/ul>\n<h3 id=\"t-1655640850443\"><b><b>2. <b>Perform \u2018status code 200\u2019 validation<\/b><\/b><\/b><\/h3>\n<p>Let us open the \u2018POSTwithParams\u2019 request from our collection<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2258\" width=\"464\" data-init-width=\"300\" height=\"316\" data-init-height=\"204\" title=\"Image 1\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-1-6-300x204.jpg\" data-width=\"464\" data-height=\"316\" style=\"\"><\/span><\/p>\n<p>Hit \u2018Send\u2019 and notice below that 200 status code is generated<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2259\" width=\"488\" data-init-width=\"300\" height=\"146\" data-init-height=\"90\" title=\"Image 2\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-2-6-300x90.jpg\" data-width=\"488\" data-height=\"146\" style=\"\"><\/span><\/p>\n<p>Let us see how to validate this status code.<\/p>\n<p>Go to the \u2018Tests\u2019 section of this Post request<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2260\" width=\"513\" data-init-width=\"300\" height=\"104\" data-init-height=\"61\" title=\"Image 3\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-3-6-300x61.jpg\" data-width=\"513\" data-height=\"104\" style=\"\"><\/span><\/p>\n<p>On the right hand side, under snippets, look for<\/p>\n<p>\u2018<b>Status code: Code is 200<\/b>\u2019<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2261\" width=\"503\" data-init-width=\"300\" height=\"174\" data-init-height=\"104\" title=\"Image 4\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-4-7-300x104.jpg\" data-width=\"503\" data-height=\"174\" style=\"\"><\/span><\/p>\n<p>Click this snippet.<\/p>\n<p>Notice below, a function is generated to validate the status 200<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2262\" width=\"537\" data-init-width=\"300\" height=\"150\" data-init-height=\"84\" title=\"Image 5\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-5-6-300x84.jpg\" data-width=\"537\" data-height=\"150\" style=\"\"><\/span><\/p>\n<p>Click \u2018Send\u2019<\/p>\n<p>Go to the \u2018Test Results\u2019 section as shown below. We would see that our Test is \u2018PASS\u2019&nbsp;<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2263\" width=\"525\" data-init-width=\"300\" height=\"441\" data-init-height=\"252\" title=\"Image 6\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-6-6-300x252.jpg\" data-width=\"525\" data-height=\"441\" style=\"\"><\/span><\/p>\n<p>We can also rename our \u2018Test\u2019 as shown below<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2264\" width=\"520\" data-init-width=\"300\" height=\"182\" data-init-height=\"105\" title=\"Image 7\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-7-6-300x105.jpg\" data-width=\"520\" data-height=\"182\" style=\"\"><\/span><\/p>\n<p>Click \u2018Send\u2019.<\/p>\n<p>Notice below the \u2018Test\u2019 is PASS and the new test name is displayed viz \u2018Validate Status code\u2019<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2265\" width=\"487\" data-init-width=\"300\" height=\"440\" data-init-height=\"271\" title=\"Image 8\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-8-6-300x271.jpg\" data-width=\"487\" data-height=\"440\" style=\"\"><\/span><\/p>\n<p>Let us intentionally change status code 200 to 201 in our code snippet as shown below<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2266\" width=\"529\" data-init-width=\"300\" height=\"210\" data-init-height=\"119\" title=\"Image 9\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-9-6-300x119.jpg\" data-width=\"529\" data-height=\"210\" style=\"\"><\/span><\/p>\n<p>Click \u2018Send\u2019<\/p>\n<p>Notice below that this time our \u2018Test\u2019 got failed and we get an assertion error. The assertion error simply means that we are expecting status code of 201 but the actual status code that we received from the server is 200. Hence our validation faied this time<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2267\" width=\"556\" data-init-width=\"300\" height=\"139\" data-init-height=\"75\" title=\"Image 10\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-10-6-300x75.jpg\" data-width=\"556\" data-height=\"139\" style=\"\"><\/span><\/p>\n<h3 id=\"t-1655640850444\"><b><b>3. <b><b>Perform string validation<\/b><\/b><\/b><\/b><\/h3>\n<p>Let us now see how to perform string validation. If we go to the \u2018Body\u2019 of this Post request (see below), we can see some string values in the body (\u201ccountry\u201d: \u201cIndia\u201d)<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2268\" width=\"514\" data-init-width=\"300\" height=\"353\" data-init-height=\"206\" title=\"Image 11\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-11-6-300x206.jpg\" data-width=\"514\" data-height=\"353\" style=\"\"><\/span><\/p>\n<p>How do we validate these strings?<\/p>\n<p>To validate strings, we have a snippet<\/p>\n<p>\u2018<b>Response body: Contains string<\/b>\u2019<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2269\" width=\"565\" data-init-width=\"300\" height=\"173\" data-init-height=\"92\" title=\"Image 12\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-12-6-300x92.jpg\" data-width=\"565\" data-height=\"173\" style=\"\"><\/span><\/p>\n<p>Click this snippet and notice below that one more function gets generated<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2270\" width=\"521\" data-init-width=\"300\" height=\"170\" data-init-height=\"98\" title=\"Image 13\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-13-6-300x98.jpg\" data-width=\"521\" data-height=\"170\" style=\"\"><\/span><\/p>\n<p>Let us replace \u201cstring_you_want_to_search\u201d with \u201cIndia\u201d<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2271\" width=\"523\" data-init-width=\"300\" height=\"58\" data-init-height=\"33\" title=\"Image 14\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-14-6-300x33.jpg\" data-width=\"523\" data-height=\"58\" style=\"\"><\/span><\/p>\n<p>Click Send.<\/p>\n<p>Notice below that the validation \u2018Body matches string\u2019 is PASS<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2272\" width=\"522\" data-init-width=\"300\" height=\"336\" data-init-height=\"193\" title=\"Image 15\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-15-6-300x193.jpg\" data-width=\"522\" data-height=\"336\" style=\"\"><\/span><\/p>\n<h3 id=\"t-1655640850445\"><b><b>4. <b><b><b>Execute all the tests in a collection as a single workflow<\/b><\/b><\/b><\/b><\/b><\/h3>\n<p>Currently, we have 4 requests in our collection<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2275\" width=\"494\" data-init-width=\"300\" height=\"287\" data-init-height=\"174\" title=\"Image 16\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-16-5-300x174.jpg\" data-width=\"494\" data-height=\"287\" style=\"\"><\/span><\/p>\n<p>Let us see how to execute all of these 4 requests as a single workflow.&nbsp;<\/p>\n<p>But before we do that, let us add \u2018200 status\u2019 validations in the 2 GET requests<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2276\" width=\"512\" data-init-width=\"293\" height=\"161\" data-init-height=\"92\" title=\"Image 17\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-17-4.jpg\" data-width=\"512\" data-height=\"161\" style=\"\"><\/span><span><img decoding=\"async\" alt=\"\" data-id=\"2277\" width=\"489\" data-init-width=\"300\" height=\"222\" data-init-height=\"136\" title=\"Image 18\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-18-4-300x136.jpg\" data-width=\"489\" data-height=\"222\" style=\"\"><\/span><span><img decoding=\"async\" alt=\"\" data-id=\"2278\" width=\"489\" data-init-width=\"300\" height=\"236\" data-init-height=\"145\" title=\"Image 19\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-19-4-300x145.jpg\" data-width=\"489\" data-height=\"236\" style=\"\"><\/span><\/p>\n<p>Save all the requests by clicking Save button<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2279\" width=\"263\" data-init-width=\"136\" height=\"191\" data-init-height=\"99\" title=\"Image 20\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-20-3.jpg\" data-width=\"263\" data-height=\"191\" style=\"\"><\/span><\/p>\n<p>Close all the requests in the Workspace<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2280\" width=\"532\" data-init-width=\"300\" height=\"232\" data-init-height=\"131\" title=\"Image 21\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-21-3-300x131.jpg\" data-width=\"532\" data-height=\"232\" style=\"\"><\/span><\/p>\n<p>Click collection<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2281\" width=\"502\" data-init-width=\"300\" height=\"269\" data-init-height=\"161\" title=\"Image 22\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-22-3-300x161.jpg\" data-width=\"502\" data-height=\"269\" style=\"\"><\/span><\/p>\n<p>On the right hand side, we will see \u2018View more actions\u2019 represented by 3 dots.<\/p>\n<p>Click these 3 dots, we will see the \u2018Run\u2019 option<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2282\" width=\"489\" data-init-width=\"300\" height=\"93\" data-init-height=\"57\" title=\"Image 23\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-23-3-300x57.jpg\" data-width=\"489\" data-height=\"93\" style=\"\"><\/span><\/p>\n<p>Click Run.<\/p>\n<p>See below. We can select\/de-select the checkboxes for the requests we want to run<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2283\" width=\"528\" data-init-width=\"300\" height=\"239\" data-init-height=\"136\" title=\"Image 24\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-24-3-300x136.jpg\" data-width=\"528\" data-height=\"239\" style=\"\"><\/span><\/p>\n<p>Leave all the options as default and click \u2018Run APIRequestsCollectionHttp\u2026\u2019<\/p>\n<p>The below window comes up showing 3 Passed and 1 Failed Test<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2284\" width=\"516\" data-init-width=\"300\" height=\"239\" data-init-height=\"139\" title=\"Image 25\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-25-3-300x139.jpg\" data-width=\"516\" data-height=\"239\" style=\"\"><\/span><\/p>\n<p>As expected, below 3 Tests Passed<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2285\" width=\"441\" data-init-width=\"279\" height=\"474\" data-init-height=\"300\" title=\"Image 26\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-26-3-279x300.jpg\" data-width=\"441\" data-height=\"474\" style=\"\"><\/span><\/p>\n<p>As expected, the below Test failed<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2286\" width=\"536\" data-init-width=\"300\" height=\"184\" data-init-height=\"103\" title=\"Image 27\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-27-3-300x103.jpg\" data-width=\"536\" data-height=\"184\" style=\"\"><\/span><\/p>\n<p>Click \u2018View Summary\u2019<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2287\" width=\"304\" data-init-width=\"193\" height=\"117\" data-init-height=\"74\" title=\"Image 28\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-28-3.jpg\" data-width=\"304\" data-height=\"117\" style=\"\"><\/span><\/p>\n<p>Notice below that we get a run summary which is self-explanatory<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2288\" width=\"524\" data-init-width=\"300\" height=\"197\" data-init-height=\"113\" title=\"Image 29\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-29-3-300x113.jpg\" data-width=\"524\" data-height=\"197\" style=\"\"><\/span><\/p>\n<p>So this is how we perform validations and execute the tests as workflows.<\/p>\n<p>In the next article, we will see how to handle cookies in postman.<\/p>\n<p>Thank you for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Perform validations and execute tests in a workflow Welcome you all to the brand new \u2018API Testing\u2019 blog series! In the previous blog, we had studied how to execute POST requests in Postman. We also studied how to chain GET and POST requests. In this tutorial, we will learn how to perform some validations. We [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2293,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1932","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","post-wrapper","thrv_wrapper"],"_links":{"self":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1932"}],"version-history":[{"count":14,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1932\/revisions"}],"predecessor-version":[{"id":2403,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1932\/revisions\/2403"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/2293"}],"wp:attachment":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}