{"id":466,"date":"2014-06-10T07:47:00","date_gmt":"2014-06-10T11:47:00","guid":{"rendered":"http:\/\/qxf2.com\/blog\/?p=466"},"modified":"2015-04-12T08:35:21","modified_gmt":"2015-04-12T12:35:21","slug":"api-testing-using-runscope","status":"publish","type":"post","link":"https:\/\/qxf2.com\/blog\/api-testing-using-runscope\/","title":{"rendered":"API Testing using Runscope"},"content":{"rendered":"<p><strong>Problem:<\/strong> Automating tests for APIs and backend services can be time consuming. Runscope is a powerful tool to help you quickly get started with API testing.<\/p>\n<p><a href=\"https:\/\/www.runscope.com\/\">Runscope<\/a> is a tool which helps us to automate web services testing. Runscope has a user friendly web interface. It also allows you to perform advanced variable manipulations and complex assertions in your tests via <a href=\"https:\/\/www.runscope.com\/docs\/radar\/scripts\">scripts<\/a>. You can also schedule tests to run regularly and receive notifications. When it comes to API testing, Runscope makes the easy things easy and the hard things possible. <\/p>\n<hr>\n<h3>When to use Runscope<\/h3>\n<p>There are a range of options that testers can use when it comes to API testing. You can choose not to test at all, get developers to do the testing, write scripts to do the testing, test the API indirectly via the front end, etc. In the past we have written about <a href=\"http:\/\/qxf2.com\/blog\/category\/mechanize-2\/\">API testing using the Python module Mechanize<\/a>. Runscope is a relatively new option that we explored and liked at <a href=\"http:\/\/www.qxf2.com\">Qxf2 Services<\/a>. Some specific times I would choose to use Runscope are when I need:<br \/>\n1. a lightweight option to do API testing<br \/>\n2. to get started quickly with API testing<br \/>\n3. to work with testers who are new to API testing<\/p>\n<p>There are two ways to create your tests: capturing live calls using Runscope URLs and creating requests from scratch. In the example below we show you how to get started with Runscope by creating requests from scratch. For this example we are going to use the public api at <a href=\"https:\/\/open.fda.gov\/\">OpenFDA<\/a>. Our test is to search for records listing a specific drug and validating the count of the five most frequently reported patient reactions.<\/p>\n<hr>\n<h3>Getting started with Runscope<\/h3>\n<p>1. Sign up for a Runscope account<br \/>\n2. Login and organize your projects<br \/>\n3. Choose a test<br \/>\n4. Create a request by adding method, URL, header, parameters etc<br \/>\n5. Run the test<br \/>\n6. Check the result<br \/>\n7. [OPTIONAL] Schedule tests and notifications<\/p>\n<hr>\n<h3>Detailed steps<\/h3>\n<p><strong>STEP 1: Sign up for a <a href=\"https:\/\/www.runscope.com\/signup\">Runscope account<\/a>.<\/strong><br \/>\nYou can sign up for a 30 day free <a href=\"https:\/\/www.runscope.com\/signup\">Runscope account<\/a><\/p>\n<p><strong>STEP 2: Login and organize your projects<\/strong><br \/>\n<a href=\"https:\/\/www.runscope.com\/signin\">Login<\/a> to your account. Create a bucket for your project and add tests in the bucket.<\/p>\n<p><a href=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Bucket.png\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-467\" src=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Bucket-1024x275.png\" alt=\"Runscope Bucket\" width=\"474\" height=\"127\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Bucket-1024x275.png 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Bucket-300x80.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Bucket.png 1206w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n<p>You can also view the bucket key which will be used when you post request using Runscope<\/p>\n<p><a href=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Bucket_Key.png\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Bucket_Key-300x120.png\" alt=\"Runscope_Bucket_Key\" width=\"300\" height=\"120\" class=\"alignnone size-medium wp-image-499\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Bucket_Key-300x120.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Bucket_Key-1024x412.png 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Bucket_Key.png 1234w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>STEP 3: Choose a test<\/strong><br \/>\nWe will test the request for <a href=\"https:\/\/open.fda.gov\/api\/reference\/\">OpenFDA<\/a>. OpenFDA is an Elasticsearch-based API that serves Food and Drug Administration publicly accessible data about drugs, devices and food. Our test is to search for records listing a specific drug and validating the count of the five most frequently reported patient reactions.<\/p>\n<p><strong>STEP 4: Create a request by adding method, URL, header, parameters etc<\/strong><br \/>\nWe are trying to create the following request in Runscope:<\/p>\n<pre lang=\"python\">\r\nhttps:\/\/api.fda.gov\/drug\/event.json?count=patient.reaction.reactionmeddrapt.exact&search=patient.drug.openfda.pharm_class_epc:\"nonsteroidal+anti-inflammatory+drug\"&limit=5\r\n<\/pre>\n<p>Click on add request where you can create request, add parameters, assertions, variables and scripts<\/p>\n<ul>\n<li>Select the type of method and\u00a0(GET, POST etc) enter the URL of the application under test<\/li>\n<li>You can add header parameters like Content Type etc<\/li>\n<li>Add the URL parameter which has to be sent as part of the query string. For this example we have added parameters like count, search and limit<\/li>\n<p><a href=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Request.png\" data-rel=\"lightbox-image-2\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Request-300x143.png\" alt=\"Runscope Request\" width=\"300\" height=\"143\" class=\"alignnone size-medium wp-image-482\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Request-300x143.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Request-1024x489.png 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_Request.png 1118w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<li>You can add assertions to specify expected value in the response for a request. If any assertion fails, when the test runs the test fails. Assertions can be added against a response header, status code, response time\/size, and content.\u00a0For our test we will add an assertion to make sure we receive Status Code 200<\/li>\n<p><a href=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Assertions.png\" data-rel=\"lightbox-image-3\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Assertions-300x125.png\" alt=\"RunScope Assertions\" width=\"300\" height=\"125\" class=\"alignnone size-medium wp-image-483\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Assertions-300x125.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Assertions.png 777w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<li>You can extract data from response and save it as variables which can be used in subsequent requests. Variables are useful for passing data and state between requests based on the outcome of previous requests in the test run.\u00a0For our test we will extract data from JSON response by using &#8216;Nested property within array&#8217;<\/li>\n<p><a href=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_variables.png\" data-rel=\"lightbox-image-4\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_variables-300x98.png\" alt=\"Runscope Variables\" width=\"300\" height=\"98\" class=\"alignnone size-medium wp-image-484\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_variables-300x98.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_variables-1024x336.png 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Runscope_variables.png 1121w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<\/ul>\n<p><strong>STEP 5: Run the test<\/strong><br \/>\nSave and run your test. Guess which button you click?<\/p>\n<p><strong>STEP 6:  Check the result<\/strong> Once a test run is completed you can view the result in the left side of the page. You can also see the detailed result along with the complete request and response which you receive.<\/p>\n<p><a href=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result.png\" data-rel=\"lightbox-image-5\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result-300x91.png\" alt=\"RunScopeResult\" width=\"300\" height=\"91\" class=\"alignnone size-medium wp-image-491\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result-300x91.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result-1024x311.png 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result.png 1105w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result_Response.png\" data-rel=\"lightbox-image-6\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result_Response-300x164.png\" alt=\"RunScope Result Response\" width=\"300\" height=\"164\" class=\"alignnone size-medium wp-image-493\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result_Response-300x164.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result_Response.png 923w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result_Body.png\" data-rel=\"lightbox-image-7\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result_Body-300x149.png\" alt=\"RunScope Result Body\" width=\"300\" height=\"149\" class=\"alignnone size-medium wp-image-492\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result_Body-300x149.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result_Body-1024x508.png 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Result_Body.png 1067w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>STEP 7: [OPTIONAL] Schedule tests and notifications<\/strong><br \/>\nClick on schedule to schedule your test to run automatically. <\/p>\n<p><a href=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Schedule.png\" data-rel=\"lightbox-image-8\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Schedule-300x93.png\" alt=\"RunScope Schedule\" width=\"300\" height=\"93\" class=\"alignnone size-medium wp-image-488\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Schedule-300x93.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Schedule-1024x317.png 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Schedule-1038x325.png 1038w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Schedule.png 1048w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>You can set notifications to your email to notify you regarding the test completion or test result. You can also post the result using Webhook Notifications.<\/p>\n<p><a href=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Schedule_Notify.png\" data-rel=\"lightbox-image-9\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/RunScope_Schedule_Notify-300x129.png\" alt=\"RunScope Notify\" width=\"300\" height=\"129\" class=\"alignnone size-medium wp-image-489\" \/><\/a><\/p>\n<hr>\n<p>Hit us up with questions and comments below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem: Automating tests for APIs and backend services can be time consuming. Runscope is a powerful tool to help you quickly get started with API testing. Runscope is a tool which helps us to automate web services testing. Runscope has a user friendly web interface. It also allows you to perform advanced variable manipulations and complex assertions in your tests [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43,38,15,42,44],"tags":[109],"class_list":["post-466","post","type-post","status-publish","format-standard","hentry","category-api-testing","category-automation","category-how-to","category-runscope","category-web-services","tag-api-testing"],"_links":{"self":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/comments?post=466"}],"version-history":[{"count":29,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/466\/revisions"}],"predecessor-version":[{"id":508,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/466\/revisions\/508"}],"wp:attachment":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/media?parent=466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/categories?post=466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/tags?post=466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}