{"componentChunkName":"component---src-pages-author-author-yaml-id-js","path":"/author/surendranath-reddy-birudala/","result":{"data":{"allMarkdownRemark":{"edges":[{"node":{"id":"fa532753-4741-55d8-b856-b8992502bc49","html":"<p>Until the modifications are introduced to production, smart companies take advantage of API testing and so do you. In both staging and production environments, API's must be checked to ensure that the software framework meets the specifications.</p>\n<p>Let's discuss how, through how your team approaches your research plan, your team can get the benefits of API testing.</p>\n<p><strong>What is API Testing?</strong>\nApplication Programming Interface is often called as <strong>API</strong>. An API is a set of methods and procedures that developers \"open up\" to other programmers to have their applications communicate and interact with other applications. Once an API is built, it is necessary to test the interface to provide truly secure, reliable and scalable connections between platforms.</p>\n<p>API testing helps identify early issues and is different from UI testing. An API receives requests and sends back responses through internet protocols including, HTTP and SMTP. API tests investigate applications that have varying API functionalities and vary the API call's parameters in different ways that verify functionality and expose failures.</p>\n<p>API testing can be done on the below aspects:</p>\n<ul>\n<li>Functional Testing</li>\n<li>Load Testing</li>\n<li>Security Testing</li>\n</ul>\n<p><strong>Functional Testing</strong> checks API's functionality, Takes payload in the form of JSON or XML and provides the response code and response body.\n<strong>Load Testing</strong> checks the performance under the specific load and determines how much traffic the API can handle before being overloaded.\n<strong>Security Testing</strong> checks vulnerabilities like authentication and sensitive data is encrypted over HTTP and includes penetration testing validating authentication.</p>\n<p><strong>Advantages of API testing during Software development</strong></p>\n<p><strong><em>1. Time efficiency</em></strong></p>\n<p>API Testing doesn't require GUI to be ready and it can be performed way early in the development cycle. The Automated API tests provide much quicker test results and significantly accelerate development workflows; thus, it helps you speed up the feedback loop and catch issues faster.</p>\n<p>In addition to that, API tests are significantly less time-consuming when compared to UI Tests. UI Tests spend much time rendering and loading the web pages and <a href=\"https://www.trychameleon.com/blog/free-ui-kits\">interface elements</a>, whereas can execute API tests in seconds. Let's take an example where a user needs to register and login from UI takes at least 3 to 5 minutes, whereas API testing takes less than 30 seconds.</p>\n<p><strong><em>2. Reduced costs</em></strong></p>\n<p>It is very closely connected with <strong>time efficiency</strong>.</p>\n<p>The cost efficiency benefit is closely connected with the previous one. Automated API tests' increased execution speed leads to more effective/efficient resource consumption and lower overall testing costs.</p>\n<p>API tests can be executed as early as the business logic is defined and before any GUI testing. So it will help you to identify the issue at the early stage. Early identification means the <strong>less expensive</strong> it is to fix it and <strong>Reduces the cost of Application changes</strong>. API testing enables the QA team to detect and resolve issues before they become a production problem, keeping project costs at bay.</p>\n<p><strong><em>3. Technology Independent</em></strong></p>\n<p>API tests are Language Independent, Since the data is interchanged using JSON or XML and compromised HTTP requests and HTTP responses. So the QA team is free to choose the language of their choice that supports these technologies((<a href=\"https://www.loginradius.com/blog/engineering/16-javascript-hacks-for-optimization/\">JavaScript</a>, Java, Ruby, <a href=\"https://www.loginradius.com/blog/engineering/python-basics-in-minutes/\">Python</a>, PHP, etc.).</p>\n<p><strong><em>4. Greater tests stability</em></strong></p>\n<p>While GUI's are dynamic and may change to accommodate new requests from stakeholders and users, API interfaces are very much stable. APIs typically come with detailed documentation, and any changes are reflected there so that QA engineers can adjust their test suites timely. And due to this inherent stability, API tests are also much easier to maintain.</p>\n<p><strong><em>5. Improved test coverage</em></strong></p>\n<p>Unlike unit tests, automated API tests are generally broader in scope and detail. While unit tests are focused on the limited functionality of components within a single application, problems often arise at the intersection where one layer's scope ends and the other begins.</p>\n<p>You won't find these issues with unit tests, but API-level tests are specifically designed to verify that all system components function as intended. API testing helps uncover potential defects in the interfaces, servers, and databases, improving the overall software quality and contributing to <a href=\"https://www.loginradius.com/identity-api/\">better user experiences</a>.</p>\n<p><strong>Efficiency gains associated with an API testing tool can include:</strong></p>\n<ul>\n<li>This will increase the number of test cycles a QA team can complete in a given timeframe.</li>\n<li>This will increase the number and variety of tests performed in a given timeframe.</li>\n<li>This will reduce the amount of time spent on manually executing tests before UAT.</li>\n</ul>\n<p><strong>Conclusion:</strong>\nAPI testing is recognized as a better fit for Continuous Testing in Agile methodologies. Not adequately tested APIs may cause issues at the API application and the calling application. It is a necessary test in software engineering.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n</style>","frontmatter":{"title":"What is API Testing? - Discover the Benefits","author":{"id":"Surendranath Reddy Birudala","github":"reddysuren","avatar":null},"date":"February 12, 2021","updated_date":null,"tags":["Automation","API Testing","Agile","Benefits"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.680672268907563,"src":"/static/80a2124798188a2366a8093c6f4d4afc/71802/api-testing.webp","srcSet":"/static/80a2124798188a2366a8093c6f4d4afc/61e93/api-testing.webp 200w,\n/static/80a2124798188a2366a8093c6f4d4afc/1f5c5/api-testing.webp 400w,\n/static/80a2124798188a2366a8093c6f4d4afc/71802/api-testing.webp 770w","sizes":"(max-width: 770px) 100vw, 770px"}}}},"fields":{"authorId":"Surendranath Reddy Birudala","slug":"/engineering/api-testing-and-benefits/"}}},{"node":{"id":"f982d599-d35c-51b5-a882-680c83d70e52","html":"<h2 id=\"what-is-rest\" style=\"position:relative;\"><a href=\"#what-is-rest\" aria-label=\"what is rest permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is Rest?</h2>\n<p>Representational State Transfer in short-form as <strong>REST</strong> defines a set of constraints for creating Web Services.\nRest API is the most-used web service technology nowadays, and it's an almost meaningless description. A REST API is a way to communicate for two computer systems over HTTP, which is similar to web browsers and servers.</p>\n<h2 id=\"what-is-bdd\" style=\"position:relative;\"><a href=\"#what-is-bdd\" aria-label=\"what is bdd permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is BDD?</h2>\n<p>BDD stands for <strong>Behavior Driven Development</strong> (BDD). Nowadays, many Organizations, to get a better advantage of testing, are taking a step forward.  </p>\n<ul>\n<li>BDD allows us to create test scripts from both the developer’s and the customer’s perspective.</li>\n<li>BDD uses human-readable descriptions of software user requirements as the basis for software tests</li>\n</ul>\n<h2 id=\"what-is-cucumber\" style=\"position:relative;\"><a href=\"#what-is-cucumber\" aria-label=\"what is cucumber permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is Cucumber?</h2>\n<p>A cucumber is an approach that supports BDD. It allows you to write tests that anyone can understand, irrespective of their technical knowledge. In BDD, users (business analysts, product owners, developers, etc..). We need to first write scenarios or acceptance tests that describe the system's behavior from the customer's point of view for review and sign-off by the product owners before developers start actual development.</p>\n<h2 id=\"what-are-the-prerequisites-to-test-rest-api-using-cucumber\" style=\"position:relative;\"><a href=\"#what-are-the-prerequisites-to-test-rest-api-using-cucumber\" aria-label=\"what are the prerequisites to test rest api using cucumber permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What are the Prerequisites to Test Rest API using Cucumber?</h2>\n<ul>\n<li>Java</li>\n<li>Editor (Eclipse, IntelliJ, etc..)</li>\n<li>Maven</li>\n</ul>\n<h3 id=\"steps-to-install-java\" style=\"position:relative;\"><a href=\"#steps-to-install-java\" aria-label=\"steps to install java permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Steps to Install Java</h3>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">http://www.oracle.com/technetwork/java/javase/downloads/index.html  </span></code></pre>\n<p>Download JDK from the above link and install it\nSet the Environment Variable on System Properties </p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">Right Click on My PC -&gt; Properties -&gt; Advanced System Settings -&gt; Environment Variables -&gt; Create New -&gt; provide path of JDK</span></code></pre>\n<h3 id=\"steps-to-install-eclipse\" style=\"position:relative;\"><a href=\"#steps-to-install-eclipse\" aria-label=\"steps to install eclipse permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Steps to Install Eclipse</h3>\n<ul>\n<li>Make Sure Java is installed on your PC.</li>\n<li>Use the below link to download Eclipse :\n<a href=\"https://eclipse.org/downloads\">Eclipse Download</a></li>\n<li>Install Eclipse on your PC </li>\n</ul>\n<p><strong>Steps to Install Maven</strong></p>\n<ul>\n<li>Use the below link to download Maven :\n<a href=\"https://maven.apache.org/download.cgi\">Maven Download</a></li>\n<li>Set the environment variable.</li>\n</ul>\n<h3 id=\"configuring-cucumber-with-maven\" style=\"position:relative;\"><a href=\"#configuring-cucumber-with-maven\" aria-label=\"configuring cucumber with maven permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Configuring Cucumber with Maven</h3>\n<ul>\n<li>\n<p>Create a Maven Project. Use below navigation.</p>\n<p><code>Open Eclipse -> File -> New -> Maven Project</code>\n</p>\n</li>\n<li>\n<p>Provide Group Id and Artifact Id and click on finish. </p>\n<p><strong>Group Id:</strong> This element indicates the organization's unique identifier or group that created the project. The groupId is one of the key identifiers of a project and is typically based on your organization's fully qualified domain name. For example, <code>com.loginradius</code>  is the designated groupId for all Maven plugins.</p>\n<p><strong>Artifact Id:</strong>  it points to the unique base name of the primary artifact generated by this project. The main or primary artifact for a project is typically a JAR file. Secondary artifacts like source bundles also use the artifactId as part of their final name.</p>\n</li>\n<li>\n<p>Open pom.xml file to add necessary dependencies </p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">&lt;dependency&gt;</span>\n<span class=\"grvsc-line\">\t&lt;groupId&gt;io.cucumber&lt;/groupId&gt;</span>\n<span class=\"grvsc-line\">\t&lt;artifactId&gt;cucumber-java&lt;/artifactId&gt;</span>\n<span class=\"grvsc-line\">\t&lt;version&gt;6.6.0&lt;/version&gt;</span>\n<span class=\"grvsc-line\">&lt;/dependency&gt;</span>\n<span class=\"grvsc-line\">&lt;dependency&gt;</span>\n<span class=\"grvsc-line\">\t&lt;groupId&gt;io.cucumber&lt;/groupId&gt;</span>\n<span class=\"grvsc-line\">\t&lt;artifactId&gt;cucumber-testng&lt;/artifactId&gt;</span>\n<span class=\"grvsc-line\">\t&lt;version&gt;6.6.0&lt;/version&gt;</span>\n<span class=\"grvsc-line\">&lt;/dependency&gt;</span>\n<span class=\"grvsc-line\">&lt;dependency&gt;</span>\n<span class=\"grvsc-line\">\t&lt;groupId&gt;io.rest-assured&lt;/groupId&gt;</span>\n<span class=\"grvsc-line\">\t&lt;artifactId&gt;rest-assured&lt;/artifactId&gt;</span>\n<span class=\"grvsc-line\">\t&lt;version&gt;4.3.0&lt;/version&gt;</span>\n<span class=\"grvsc-line\">\t&lt;scope&gt;test&lt;/scope&gt;</span>\n<span class=\"grvsc-line\">&lt;/dependency&gt;</span>\n<span class=\"grvsc-line\">&lt;dependency&gt;</span>\n<span class=\"grvsc-line\">\t&lt;groupId&gt;org.testng&lt;/groupId&gt;</span>\n<span class=\"grvsc-line\">\t&lt;artifactId&gt;testng&lt;/artifactId&gt;</span>\n<span class=\"grvsc-line\">\t&lt;version&gt;7.1.0&lt;/version&gt;</span>\n<span class=\"grvsc-line\">\t&lt;scope&gt;test&lt;/scope&gt;</span>\n<span class=\"grvsc-line\">&lt;/dependency&gt;</span></code></pre>\n</li>\n</ul>\n<p> Now we need three Important files.</p>\n<ul>\n<li>Feature file</li>\n<li>StepDefination file</li>\n<li>Runner file</li>\n</ul>\n<p> <strong>Feature File:</strong>  It's a entry point to the cucumber. We use Gherkins to write the feature file. This is the file where you will describe your descriptive language(Gherkin uses simple English). A feature file can contains a Scenario or List of Scenario. A sample Feature file is below</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">Feature: Login Functionality</span>\n<span class=\"grvsc-line\">@validLogin</span>\n<span class=\"grvsc-line\">Scenario: User Should Login With Valid Credentials </span>\n<span class=\"grvsc-line\">   Given Post Login API</span>\n<span class=\"grvsc-line\">   When Provide Valid Credential</span>\n<span class=\"grvsc-line\">   Then Status_code equals 200    </span>\n<span class=\"grvsc-line\">   And  response contains IsLogin equals &quot;true&quot;</span>\n<span class=\"grvsc-line\">@invalidLogin    </span>\n<span class=\"grvsc-line\">Scenario Outline: Email and Password Validation in Login API </span>\n<span class=\"grvsc-line\">   Given Post Login API</span>\n<span class=\"grvsc-line\">   When Provide different combinations to &quot;&lt;email&gt;&quot;&quot;&lt;password&gt;&quot;</span>\n<span class=\"grvsc-line\">   Then Status_code equals &lt;statuscode&gt;    </span>\n<span class=\"grvsc-line\">   And  response contains message equals &quot;&lt;message&gt;&quot;</span>\n<span class=\"grvsc-line\">   Examples:</span>\n<span class=\"grvsc-line\">   |email     \t\t|password    | statuscode |  message</span>\n<span class=\"grvsc-line\">   |          \t\t|            |   401      | Required email and password</span>\n<span class=\"grvsc-line\">   | abc\t  \t|            |   401      | Email format is incorrect</span>\n<span class=\"grvsc-line\">   | abc@mail7.io  \t|\t     |   401      | Required password</span>\n<span class=\"grvsc-line\">   | abc@mail7.io   \t| password   |   401      | Email and Password combination Incorrect</span></code></pre>\n<p> Save the above code as login.feature </p>\n<ul>\n<li><strong>Feature:</strong> It indicates the name of the feature under the test.</li>\n<li><strong>Description:</strong> It indicates a meaningful description of the feature (Optional).</li>\n<li><strong>scenario:</strong> scenario indicates the steps and expected outcomes for a particular test case.</li>\n<li><strong>Scenario Outline:</strong> Single scenario can be executed for multiple data sets using scenario outlines. The data is provided by a tabular structure separated by (I I).</li>\n<li><strong>Given:</strong> Prerequisite before the test steps get executed.</li>\n<li><strong>When:</strong> Specific condition which should match to execute the next step.</li>\n<li><strong>Then:</strong> What should happen if the condition mentioned in WHEN is satisfied.</li>\n<li><strong>Examples:</strong> Its a tabular format input data to pass to scenario outline.</li>\n<li><strong>&#x3C;>:</strong> anything if you write between is variable. </li>\n</ul>\n<p><strong>StepDefinition:</strong>\nNow you have your feature file ready with test scenarios defined. However, our job is not done yet. Cucumber doesn't know when should execute which part of code. So StepDefinition acts as an intermediate to your runner and feature file. It stores the mapping between each step of the scenario in the Feature file. So when you run the scenario, it will scan the stepDefination file to check matched glue.</p>\n<p><strong>How to write step definition:</strong>\nWe have a chrome extension(Tidy Gherkin) to convert your feature into a step definition.<br>\nCopy your scenario from the feature file and paste it in Tidy Gherkin and click on Java Steps; copy the Java Steps.\nCreate a new file name a StepDefinition.java and paste the Java Steps</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"java\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">package</span><span class=\"mtk1\"> com.loginradius.login</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk14\">import</span><span class=\"mtk1\"> cucumber.api.java.en.</span><span class=\"mtk14\">G</span><span class=\"mtk1\">iven;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">import</span><span class=\"mtk1\"> cucumber.api.java.en.When;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">import</span><span class=\"mtk1\"> cucumber.api.java.en.Then;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">import</span><span class=\"mtk1\"> cucumber.api.java.en.And;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">import</span><span class=\"mtk1\"> cucumber.api.junit.Cucumber;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">import</span><span class=\"mtk1\"> org.junit.runner.RunWith;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">import</span><span class=\"mtk1\"> </span><span class=\"mtk4\">static</span><span class=\"mtk1\"> io.restassured.RestAssured.given;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">import</span><span class=\"mtk1\"> </span><span class=\"mtk4\">static</span><span class=\"mtk1\"> org.testng.Assert.assertTrue;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">import</span><span class=\"mtk1\"> io.restassured.http.ContentType;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">import</span><span class=\"mtk1\"> io.restassured.response.Response;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">import</span><span class=\"mtk1\"> io.restassured.specification.RequestSpecification;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">import</span><span class=\"mtk1\"> io.restassured.RestAssured;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk4\">class</span><span class=\"mtk1\"> </span><span class=\"mtk10\">StepDefinition</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t</span><span class=\"mtk4\">private</span><span class=\"mtk1\">  </span><span class=\"mtk4\">static</span><span class=\"mtk1\">  </span><span class=\"mtk4\">final</span><span class=\"mtk1\">  </span><span class=\"mtk10\">String</span><span class=\"mtk1\">  </span><span class=\"mtk12\">BASE_URL</span><span class=\"mtk1\">  =  </span><span class=\"mtk8\">&quot;https://www.loginradius.com&quot;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t</span><span class=\"mtk10\">String</span><span class=\"mtk1\"> </span><span class=\"mtk12\">email</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">&quot;abcxyz@mail7.io;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">\tString password = &quot;</span><span class=\"mtk1\">password</span><span class=\"mtk8\">&quot;;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">\tRequestSpecification request;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">\tprivate  static  Response response;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">\tprivate  static  String  jsonString;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">    @Given(&quot;</span><span class=\"mtk10\">Post</span><span class=\"mtk1\"> </span><span class=\"mtk10\">Login</span><span class=\"mtk1\"> API</span><span class=\"mtk8\">&quot;)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">    public void post_login_api() {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">\t    RestAssured.baseURI  =  BASE_URL;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">\t\trequest  =  RestAssured.given();</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">\t\trequest.header(&quot;</span><span class=\"mtk1\">Content-Type</span><span class=\"mtk8\">&quot;,  &quot;</span><span class=\"mtk1\">application/json</span><span class=\"mtk8\">&quot;);    </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">    }</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">    </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">   @When(&quot;</span><span class=\"mtk10\">Provide</span><span class=\"mtk1\"> </span><span class=\"mtk10\">Valid</span><span class=\"mtk1\"> Credential</span><span class=\"mtk8\">&quot;)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">    public void provide_valid_credential() {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk8\">      response  =  request.body(&quot;</span><span class=\"mtk1\">{ \\</span><span class=\"mtk8\">&quot;userName</span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">:</span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">&quot;</span><span class=\"mtk1\">  +  email  +  </span><span class=\"mtk8\">&quot;</span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">, </span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">password</span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">:</span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">&quot;</span><span class=\"mtk1\">  +  password  +  </span><span class=\"mtk8\">&quot;</span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">}&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t\t\t\t\t  .</span><span class=\"mtk11\">post</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;/user/login&quot;</span><span class=\"mtk1\">);\t</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    }</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">   @</span><span class=\"mtk10\">Then</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Status_code equals {int}&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk10\">void</span><span class=\"mtk1\"> </span><span class=\"mtk11\">statuscode_equals_</span><span class=\"mtk1\">(</span><span class=\"mtk10\">int</span><span class=\"mtk1\"> agr) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t    </span><span class=\"mtk12\">Assert</span><span class=\"mtk1\">.</span><span class=\"mtk11\">assertEquals</span><span class=\"mtk1\">(arg, </span><span class=\"mtk12\">response</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getStatusCode</span><span class=\"mtk1\">());</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    }</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t@</span><span class=\"mtk10\">And</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;response contains IsPosted equals {string}&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk10\">void</span><span class=\"mtk1\"> </span><span class=\"mtk11\">response_contains_IsPosted_equals_</span><span class=\"mtk1\">(</span><span class=\"mtk10\">String</span><span class=\"mtk1\"> message) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t    </span><span class=\"mtk12\">Assert</span><span class=\"mtk1\">.</span><span class=\"mtk11\">assertEquals</span><span class=\"mtk1\">(message, </span><span class=\"mtk11\">getJsonPath</span><span class=\"mtk1\">(response, </span><span class=\"mtk8\">&quot;IsPosted&quot;</span><span class=\"mtk1\">));</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    }\t</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">   @</span><span class=\"mtk10\">And</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;response contains message equals {string}&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk10\">void</span><span class=\"mtk1\"> </span><span class=\"mtk11\">response_contains_equals_</span><span class=\"mtk1\">(</span><span class=\"mtk10\">String</span><span class=\"mtk1\"> message) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t    </span><span class=\"mtk12\">Assert</span><span class=\"mtk1\">.</span><span class=\"mtk11\">assertEquals</span><span class=\"mtk1\">(message, </span><span class=\"mtk11\">getJsonPath</span><span class=\"mtk1\">(response, </span><span class=\"mtk8\">&quot;message&quot;</span><span class=\"mtk1\">));</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    }</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t@</span><span class=\"mtk10\">When</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Provide different combinations to {string}, {string}&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk10\">void</span><span class=\"mtk1\"> </span><span class=\"mtk11\">provide_different_combinations_to_somethingsomething</span><span class=\"mtk1\">(</span><span class=\"mtk10\">String</span><span class=\"mtk1\"> email, </span><span class=\"mtk10\">String</span><span class=\"mtk1\"> password){</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t    response = </span><span class=\"mtk12\">request</span><span class=\"mtk1\">.</span><span class=\"mtk11\">body</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;{ </span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">userName</span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">:</span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">&quot;</span><span class=\"mtk1\"> + email + </span><span class=\"mtk8\">&quot;</span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">, </span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">password</span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">:</span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">&quot;</span><span class=\"mtk1\"> + password + </span><span class=\"mtk8\">&quot;</span><span class=\"mtk6\">\\&quot;</span><span class=\"mtk8\">}&quot;</span><span class=\"mtk1\">) .</span><span class=\"mtk11\">post</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;/user/login&quot;</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    }</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t</span><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk10\">String</span><span class=\"mtk1\"> </span><span class=\"mtk11\">getJsonPath</span><span class=\"mtk1\">(</span><span class=\"mtk10\">Response</span><span class=\"mtk1\"> response, </span><span class=\"mtk10\">String</span><span class=\"mtk1\"> key) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t</span><span class=\"mtk10\">String</span><span class=\"mtk1\"> </span><span class=\"mtk12\">resp</span><span class=\"mtk1\"> = </span><span class=\"mtk12\">response</span><span class=\"mtk1\">.</span><span class=\"mtk11\">asString</span><span class=\"mtk1\">();</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t</span><span class=\"mtk10\">JsonPath</span><span class=\"mtk1\"> </span><span class=\"mtk12\">js</span><span class=\"mtk1\"> = </span><span class=\"mtk15\">new</span><span class=\"mtk1\"> </span><span class=\"mtk11\">JsonPath</span><span class=\"mtk1\">(resp);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t</span><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk12\">js</span><span class=\"mtk1\">.</span><span class=\"mtk11\">get</span><span class=\"mtk1\">(key).</span><span class=\"mtk11\">toString</span><span class=\"mtk1\">();</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<p>Now we have Our Feature file and StepDefinition Ready, we need a runner file to run our Test Scenario's</p>\n<p><strong>Runner File:</strong>\nA runner will help us to run the feature file and acts as an interlink between the feature file and StepDefinition Class\nBelow is the code which will help you to run the tests</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"java\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">package</span><span class=\"mtk1\"> runner;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">import</span><span class=\"mtk1\"> io.cucumber.testng.CucumberOptions;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">@</span><span class=\"mtk10\">CucumberOptions</span><span class=\"mtk1\">(</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\tfeatures= {</span><span class=\"mtk8\">&quot;feature_files/login.feature&quot;</span><span class=\"mtk1\">},</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        glue= {</span><span class=\"mtk8\">&quot;step_definations/StepDefinitation.java&quot;</span><span class=\"mtk1\">},</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        tags= </span><span class=\"mtk8\">&quot;@validLogin&quot;</span><span class=\"mtk1\">,    </span><span class=\"mtk3\">// based on tags scenarios will run</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        monochrome=</span><span class=\"mtk4\">true</span><span class=\"mtk1\">, dryRun=</span><span class=\"mtk4\">false</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t)\t</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">public</span><span class=\"mtk1\">  </span><span class=\"mtk4\">class</span><span class=\"mtk1\">  </span><span class=\"mtk10\">TestRunner</span><span class=\"mtk1\">  {</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<p>Now We have Feature, StepDefinition, and runner files ready, We can run the runner file to see the results.</p>\n<h2 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h2>\n<p>Cucumber is very useful in understanding the overall testing process without having coding knowledge. Since it uses simple English to write the feature file and makes developer, QA and other stakeholders on same page before starting the actual development.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk1 { color: #D4D4D4; }\n  .dark-default-dark .mtk14 { color: #F44747; }\n  .dark-default-dark .mtk10 { color: #4EC9B0; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n  .dark-default-dark .mtk6 { color: #D7BA7D; }\n  .dark-default-dark .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n  .dark-default-dark .mtk3 { color: #6A9955; }\n</style>","frontmatter":{"title":"Automating Rest API's using Cucumber and Java","author":{"id":"Surendranath Reddy Birudala","github":"reddysuren","avatar":null},"date":"November 05, 2020","updated_date":null,"tags":["Automation","Cucumber","Rest API","Java"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/1775ed5790237a2d1ac5fbda108bc357/58556/cucumber_rest_assured.webp","srcSet":"/static/1775ed5790237a2d1ac5fbda108bc357/61e93/cucumber_rest_assured.webp 200w,\n/static/1775ed5790237a2d1ac5fbda108bc357/1f5c5/cucumber_rest_assured.webp 400w,\n/static/1775ed5790237a2d1ac5fbda108bc357/58556/cucumber_rest_assured.webp 800w,\n/static/1775ed5790237a2d1ac5fbda108bc357/99238/cucumber_rest_assured.webp 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}}},"fields":{"authorId":"Surendranath Reddy Birudala","slug":"/engineering/rest-api-cucumber-blog/"}}}]},"authorYaml":{"id":"Surendranath Reddy Birudala","bio":null,"github":"reddysuren","stackoverflow":null,"linkedin":null,"medium":null,"twitter":null,"avatar":null}},"pageContext":{"id":"Surendranath Reddy Birudala","__params":{"id":"surendranath-reddy-birudala"}}},"staticQueryHashes":["1171199041","1384082988","2100481360","23180105","528864852"]}