{"id":669,"date":"2019-11-18T12:31:23","date_gmt":"2019-11-18T12:31:23","guid":{"rendered":"https:\/\/www.dhruvsoft.com\/blog\/?p=669"},"modified":"2024-07-26T09:41:27","modified_gmt":"2024-07-26T09:41:27","slug":"runscope-primer-using-runscope-for-api-testing","status":"publish","type":"post","link":"https:\/\/www.dhruvsoft.com\/blog\/runscope-primer-using-runscope-for-api-testing\/","title":{"rendered":"Runscope Primer &#8211; Using Runscope for API testing"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Runscope\u00a0is one of the popular solutions for API performance testing, monitoring and debugging. Runscope helps in creating, managing and executing functional API tests and monitors.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Runscope-Primer-Using-Runscope-for-API-testing-1024x576.png\" alt=\"Runscope Primer - Using Runscope for API testing\" class=\"wp-image-675\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Runscope-Primer-Using-Runscope-for-API-testing-1024x576.png 1024w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Runscope-Primer-Using-Runscope-for-API-testing-300x169.png 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Runscope-Primer-Using-Runscope-for-API-testing-768x432.png 768w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Runscope-Primer-Using-Runscope-for-API-testing.png 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">The most common use case where Runscope is used is to test the API. You can execute one or more HTTP requests sequentially&nbsp;to evaluate the performance, up time and correctness.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Users can define Assertions for each request; a test passes if all the assertion pass, a test fails if any of the assertion fail. Also users can schedule test can be used for ongoing monitoring.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One can define an assertion in a way which should have source and target values. Users can compare the extracted data with the target value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">User can create a test case as shown in below image<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/create-a-test-case.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"384\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/create-a-test-case-1024x384.jpg\" alt=\"Using Run-scope for API testing create a test case\" class=\"wp-image-670\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/create-a-test-case-1024x384.jpg 1024w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/create-a-test-case-300x112.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/create-a-test-case-768x288.jpg 768w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/create-a-test-case.jpg 1027w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">After creating a test you will see a request step like below<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><a href=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/After-creating-a-test-you-will-see-a-request-step.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/After-creating-a-test-you-will-see-a-request-step.jpg\" alt=\"After creating a test you will see a request step\" class=\"wp-image-671\" width=\"840\" height=\"371\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/After-creating-a-test-you-will-see-a-request-step.jpg 927w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/After-creating-a-test-you-will-see-a-request-step-300x133.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/After-creating-a-test-you-will-see-a-request-step-768x340.jpg 768w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/a><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">From here, you can give Endpoint url to test with request types either Get, Post, Put etc;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can define assertion by clicking on Assertion tab which has to compare target value with the requested value<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the request passes we get a status code of 200 for that request. If the request is bad we will get the status code of 400.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 ez-toc-wrap-left-text counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.dhruvsoft.com\/blog\/runscope-primer-using-runscope-for-api-testing\/#Variables\" >Variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.dhruvsoft.com\/blog\/runscope-primer-using-runscope-for-api-testing\/#Pre_request_script\" >Pre request script<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.dhruvsoft.com\/blog\/runscope-primer-using-runscope-for-api-testing\/#Post_response_script\" >Post response script<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.dhruvsoft.com\/blog\/runscope-primer-using-runscope-for-api-testing\/#Run_your_test\" >Run your test<\/a><\/li><\/ul><\/nav><\/div>\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Variables\"><\/span>Variables<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">You can define a variable which can be used in a subsequent request and also for storing a value. We can define a variable in two ways<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Local variable<\/li><li>Environment&nbsp; variable<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Local variable will be used for only one request in a defined place and on the other hand, environment variable is used for all the request that can define in a Test i.e, we can inherit and use in another request<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Pre_request_script\"><\/span>Pre request script<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">From here you can add a script that can be used to run initially. For example, if you want to clear a header value which is coming from environment variables before executing a request<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">delete request.headers[\u00e2\u20ac\u0153your_header\u00e2\u20ac&#x2122;];<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This line of script is used to delete a header for that request.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Post_response_script\"><\/span>Post response script<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">You can add a script which should be run after the request executed. For example, if you want to store an Id of record that can use in another request of a test.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Headers, Body, and Authentication can be added in a single request<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can create a condition before executing a request. If the condition passes, then that particular request can execute<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"108\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/create-a-condition-before-executing-a-request-1024x108.jpg\" alt=\"create a condition before executing a request\" class=\"wp-image-672\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/create-a-condition-before-executing-a-request-1024x108.jpg 1024w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/create-a-condition-before-executing-a-request-300x32.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/create-a-condition-before-executing-a-request-768x81.jpg 768w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/create-a-condition-before-executing-a-request.jpg 1050w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">You can use one request as subtest to another request by clicking on add step<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"112\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/use-one-request-as-subtest-to-another-request-by-clicking-on-add-step-1024x112.jpg\" alt=\"use one request as subtest to another request by clicking on add step\" class=\"wp-image-673\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/use-one-request-as-subtest-to-another-request-by-clicking-on-add-step-1024x112.jpg 1024w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/use-one-request-as-subtest-to-another-request-by-clicking-on-add-step-300x33.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/use-one-request-as-subtest-to-another-request-by-clicking-on-add-step-768x84.jpg 768w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/use-one-request-as-subtest-to-another-request-by-clicking-on-add-step.jpg 1033w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Run_your_test\"><\/span>Run your test<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Click&nbsp;<strong>Save &amp; Run<\/strong>&nbsp;to start a new test run. The request will be executed and upon completion, each assertion will be checked. If everything checks out, you should see that the test run&nbsp;<strong>Passed<\/strong>. Select the test run from the results list to view the full HTTP request, response, and test output.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Refer below image to know the details<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"607\" height=\"380\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Select-the-test-run-from-the-results.jpg\" alt=\"Select the test run from the results\" class=\"wp-image-674\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Select-the-test-run-from-the-results.jpg 607w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2019\/11\/Select-the-test-run-from-the-results-300x188.jpg 300w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Runscope\u00a0is one of the popular solutions for API performance testing, monitoring and debugging. Runscope helps in creating, managing and executing functional API tests and monitors.<\/p>\n","protected":false},"author":21,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-669","post","type-post","status-publish","format-standard","hentry","category-salesforce-com-crm","entry"],"_links":{"self":[{"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/posts\/669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/comments?post=669"}],"version-history":[{"count":0,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/posts\/669\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/media?parent=669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/categories?post=669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/tags?post=669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}