www.pcloudy.com
Open in
urlscan Pro
69.167.165.176
Public Scan
Submitted URL: http://www.pcloudy.com/blogs/api-test-automation-with-restassured-library-and-cucumber-bdd-framework/
Effective URL: https://www.pcloudy.com/blogs/api-test-automation-with-restassured-library-and-cucumber-bdd-framework/
Submission: On April 23 via manual from PL — Scanned from PL
Effective URL: https://www.pcloudy.com/blogs/api-test-automation-with-restassured-library-and-cucumber-bdd-framework/
Submission: On April 23 via manual from PL — Scanned from PL
Form analysis
2 forms found in the DOM<form class="schedule_Btn" data-faitracker-form-bind="true">
<a href="https://sstsauth.opkeyone.com/auth/realms/KC_SSTS_Auth/protocol/openid-connect/auth?client_id=SSTS&redirect_uri=https%3A%2F%2Fsignup.pcloudyunified.com%2Fstudio%2Fsignin&state=220b7695-6f31-4947-89b5-321cda1473f2&response_mode=fragment&response_type=code&scope=openid&nonce=93943101-396b-4269-97af-e0e72c45fc57" class="secondaryBtn">Login</a>
<a href="https://signup.pcloudyunified.com/" class="primary">Start a Free
Trial</a>
</form>
POST https://forms.hsforms.com/submissions/v3/public/submit/formsnext/multipart/4378242/e80420cf-dcd5-4e6d-90e6-b37ae8a5b164
<form id="hsForm_e80420cf-dcd5-4e6d-90e6-b37ae8a5b164" method="POST" accept-charset="UTF-8" enctype="multipart/form-data" novalidate=""
action="https://forms.hsforms.com/submissions/v3/public/submit/formsnext/multipart/4378242/e80420cf-dcd5-4e6d-90e6-b37ae8a5b164"
class="hs-form-private hsForm_e80420cf-dcd5-4e6d-90e6-b37ae8a5b164 hs-form-e80420cf-dcd5-4e6d-90e6-b37ae8a5b164 hs-form-e80420cf-dcd5-4e6d-90e6-b37ae8a5b164_4ce25dd6-5f75-4a31-a6d5-fbb14c1288c2 mySiteForms hs-form"
target="target_iframe_e80420cf-dcd5-4e6d-90e6-b37ae8a5b164" data-instance-id="4ce25dd6-5f75-4a31-a6d5-fbb14c1288c2" data-form-id="e80420cf-dcd5-4e6d-90e6-b37ae8a5b164" data-portal-id="4378242"
data-test-id="hsForm_e80420cf-dcd5-4e6d-90e6-b37ae8a5b164" data-faitracker-form-bind="true">
<div class="hs_email hs-email hs-fieldtype-text field hs-form-field"><label id="label-email-e80420cf-dcd5-4e6d-90e6-b37ae8a5b164" class="" placeholder="Enter your " for="email-e80420cf-dcd5-4e6d-90e6-b37ae8a5b164"><span></span></label>
<legend class="hs-field-desc" style="display: none;"></legend>
<div class="input"><input id="email-e80420cf-dcd5-4e6d-90e6-b37ae8a5b164" name="email" required="" placeholder="Business email*" type="email" class="hs-input" inputmode="email" autocomplete="email" value=""></div>
</div>
<div class="hs_page_url hs-page_url hs-fieldtype-text field hs-form-field" style="display: none;"><label id="label-page_url-e80420cf-dcd5-4e6d-90e6-b37ae8a5b164" class="" placeholder="Enter your Page URL"
for="page_url-e80420cf-dcd5-4e6d-90e6-b37ae8a5b164"><span>Page URL</span></label>
<legend class="hs-field-desc" style="display: none;"></legend>
<div class="input"><input name="page_url" class="hs-input" type="hidden" value=""></div>
</div>
<div class="hs_product_type hs-product_type hs-fieldtype-select field hs-form-field" style="display: none;"><label id="label-product_type-e80420cf-dcd5-4e6d-90e6-b37ae8a5b164" class="" placeholder="Enter your Product Type"
for="product_type-e80420cf-dcd5-4e6d-90e6-b37ae8a5b164"><span>Product Type</span></label>
<legend class="hs-field-desc" style="display: none;"></legend>
<div class="input"><input name="product_type" class="hs-input" type="hidden" value="pCloudy"></div>
</div>
<div class="hs_submit hs-submit">
<div class="hs-field-desc" style="display: none;"></div>
<div class="actions"><input type="submit" class="hs-button primary large" value="Subscribe" data-faitracker-form-bind="true"></div>
</div><input name="hs_context" type="hidden"
value="{"embedAtTimestamp":"1713868463145","formDefinitionUpdatedAt":"1688368968060","lang":"en","disableCookieSubmission":"true","clonedFromForm":"c9013adf-0773-4f19-a8d3-0d3c4d0bbafb","renderRawHtml":"true","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","pageTitle":"API Test Automation with RestAssured Library and Cucumber BDD Framework","pageUrl":"https://www.pcloudy.com/blogs/api-test-automation-with-restassured-library-and-cucumber-bdd-framework/","isHubSpotCmsGeneratedPage":false,"hutk":"9833576fec5d9f3e4c164bfd35b8782b","__hsfp":3876999637,"__hssc":"219367942.1.1713868466212","__hstc":"219367942.9833576fec5d9f3e4c164bfd35b8782b.1713868466212.1713868466212.1713868466212.1","formTarget":"#hbspt-form-4ce25dd6-5f75-4a31-a6d5-fbb14c1288c2","rumScriptExecuteTime":1834.599998474121,"rumTotalRequestTime":2096.300003051758,"rumTotalRenderTime":2134.900001525879,"rumServiceResponseTime":261.7000045776367,"rumFormRenderTime":38.599998474121094,"connectionType":"4g","firstContentfulPaint":0,"largestContentfulPaint":0,"locale":"en","timestamp":1713868466235,"originalEmbedContext":{"portalId":"4378242","formId":"e80420cf-dcd5-4e6d-90e6-b37ae8a5b164","region":"na1","target":"#hbspt-form-4ce25dd6-5f75-4a31-a6d5-fbb14c1288c2","isBuilder":false,"isTestPage":false,"isPreview":false,"cssClass":"mySiteForms","isMobileResponsive":true},"correlationId":"4ce25dd6-5f75-4a31-a6d5-fbb14c1288c2","renderedFieldsIds":["email","page_url","product_type"],"captchaStatus":"NOT_APPLICABLE","emailResubscribeStatus":"NOT_APPLICABLE","isInsideCrossOriginFrame":false,"source":"forms-embed-1.5064","sourceName":"forms-embed","sourceVersion":"1.5064","sourceVersionMajor":"1","sourceVersionMinor":"5064","allPageIds":{},"_debug_embedLogLines":[{"clientTimestamp":1713868463221,"level":"INFO","message":"Retrieved customer callbacks used on embed context: [\"onFormSubmit\"]"},{"clientTimestamp":1713868463222,"level":"INFO","message":"Retrieved pageContext values which may be overriden by the embed context: {\"pageTitle\":\"API Test Automation with RestAssured Library and Cucumber BDD Framework\",\"pageUrl\":\"https://www.pcloudy.com/blogs/api-test-automation-with-restassured-library-and-cucumber-bdd-framework/\",\"userAgent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36\",\"isHubSpotCmsGeneratedPage\":false}"},{"clientTimestamp":1713868463223,"level":"INFO","message":"Retrieved countryCode property from normalized embed definition response: \"PL\""},{"clientTimestamp":1713868466231,"level":"INFO","message":"Retrieved analytics values from API response which may be overriden by the embed context: {\"hutk\":\"9833576fec5d9f3e4c164bfd35b8782b\"}"}]}"><iframe
name="target_iframe_e80420cf-dcd5-4e6d-90e6-b37ae8a5b164" style="display: none;" data-lf-form-tracking-inspected-yegkb8lqamp7ep3z="true" data-lf-yt-playback-inspected-yegkb8lqamp7ep3z="true"
data-lf-vimeo-playback-inspected-yegkb8lqamp7ep3z="true"></iframe>
</form>
Text Content
Skip to content Webinar 24th Apr : AI-Augmented App Testing Strategies to Accelerate Delivery & Eliminate Technical Debt - Register Now! * Company About Us Customer Partners Latest News * Product TEST AUTOMATION No Code Test Builder Record & Playback and Synthetic Test Data Generation for Easy Test Creation Simplified maintenance Modular Approach and AI Augmented Self Healing of Tests Extended Test Coverage Visual Regression & Accessibility Testing in single click Integrated Tests Multi Platform Test Cases across Web, Mobile Desktop & APIs TEST INFRASTRUCTURE Device Lab Run Manual and Automated Tests at Scale on Our Real Device Lab Browser Lab Test your Web Apps on Real Browsers and OS Combinations TEST MANAGEMENT Test Analytics Debug Faster with Auto Generated Comprehensive Test Reports In Built Test Management Holistic View of Manual & Automated Tests throughout SDLC 1. IntegrationsSee all 2. Application Types Mobile App Web App Desktop App Use Cases Real Device Testing Cross Browser Testing Visual Testing Accessibility Testing * Solution SMBs & Startups Enterprises * Pricing * Resources Blog Webinar Videos Case Study Whitepaper Latest Whitepaper A Test Efficiency Playbook for CIOs & Digital Leaders Most Enterprises and Global Capability Centers (GCCs) face challenges in implementing new strategies due to their never-ending decision-making process. But what if we were to help you simplify this process... Learn More * Support Documentation Pcloudy Academy Contact Us API Reference Login Start a Free Trial BLOGS GET USEFUL INFORMATION ON APPS TESTING AND DEVELOPMENT Shivani Sinha | Posted on July 12, 2023July 10, 2023 | 2 min Read API TEST AUTOMATION WITH RESTASSURED LIBRARY AND CUCUMBER BDD FRAMEWORK INTRODUCTION TO REST ASSURED LIBRARY REST (Representational State Transfer) is an architecture that consumes HTTP calls for inter-system communication where a client can access the server resource with a unique URI and a response of the resource is returned. The URI of the resource acts as a resource identifier and HTTP operations like GET, POST, PUT, PATCH, DELETE can be performed on the resource. REST Assured is a Java library that leverages developing powerful maintainable tests for Restful APIs with domain specific language(DSL). Let’s discuss some of the salient features of the Rest Assured Library: 1. It’s an open source application, hence, there’s no license cost 2. Uses the commonly used programming language Java 3. Makes API testing and validation of Rest services easy and smooth 4. GPath is used to traverse through the response which is great for both XML and JSON response read 5. Validations on JSON schema can be applied 6. Effortless integration can be done with other testing frameworks such as TestNG, JUnit etc 7. Supports API automation for all types of HTTP methods such as GET, POST, PUT, DELETE, PATCH etc 8. Provides support of BDD Gherkin language which leads to clean coding and easy readability INTRODUCTION TO CUCUMBER FRAMEWORK Cucumber is an open source testing framework that supports Behavior Driven Development (BDD) and is a widely used framework that testers leverage to write test cases in simple English language called Gherkin. To make the testing process and testing flow easily understandable by non-techies, many organizations want to integrate Cucumber framework with Selenium or Rest Assured for application automation. Since Cucumber allows writing tests and scenarios in simple English plain text, it becomes a primary advantage for many team members who are Business Analysts, Project Managers, Manual Testers and for any other non-technical persons to view and understand the testing workflow with much ease. Cucumber is //.[known as Behavior Driven Development (BDD) framework as it can help anyone to grab the functional behavior of an application by just reading out the feature file. Cucumber framework is basically divided in three different components: 1. Feature File: This file provides high level information of an application under test in form of test feature, test scenarios, test tags, test cases, test data etc. Below are few a components that are used to create feature file: * Feature- Defines the feature that is planned to be tested along with its objective. * Scenario- Defines the particular test scenario for which test flow has to be created. * Scenario Outline- Defines the particular test scenario against different test data provided in a tabular structure separated by pipe symbol( | ) * Tags- Defines a name of the tag for each scenario which helps in organizing or grouping all the test scenarios of the feature file. Tags can be used on the above Feature keyword as well to indicate which feature file needs to be executed. * Given- Defines pre-condition of a particular test scenario * When- Defines an action or interaction with an application yet to be performed * And- Defines extra action related linked with previous action * Then- Defines the expected output of the test and the post action to be performed * Examples- Defines set of test data for the test case written in “Scenario Outline” 2. Step Definition File: The step definitions file is created to link all the feature file test case steps to code. Few annotations like Given, When, Then etc are used in step definition files to map the test case steps for their code execution. For a test case to be executed, the annotated description must match the test step mentioned in the feature file. 3. Test Runner File: This file acts as a driver file for your test suite that drives or runs the step definition files based on feature files. The Test Runner file basically consists of the paths to your feature and step definition file along with the tags to be executed and required for cucumber based test reporting. For cucumber based HTML reporting, it also provides you an option to add a plugin to generate insightful reports. INTEGRATING REST ASSURED LIBRARY WITH CUCUMBER FRAMEWORK Now that we are aware of the Rest Assured library and Cucumber framework, lets practically understand how we can create the test scenarios and learn the steps for api testing against different sets of test data. To integrate the rest assured library with the cucumber framework, we would need to create different files like feature, step definition and runner file as discussed earlier. Before moving forward, let’s create a simple maven project and import all the dependencies of the rest assured library and of the cucumber framework in the pom.xml file. <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-java</artifactId> <version>1.2.5</version> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-jvm-deps</artifactId> <version>1.0.5</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-testng</artifactId> <version>1.2.5</version> <scope>compile</scope> <exclusions> <exclusion> <groupId>junit</groupId> <artifactId>junit</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>net.masterthought</groupId> <artifactId>cucumber-reporting</artifactId> <version>5.0.2</version> </dependency> <dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>4.3.2</version> <scope>test</scope> </dependency> <dependency> <groupId>io.rest-assured</groupId> <artifactId>json-path</artifactId> <version>4.3.2</version> <scope>test</scope> </dependency> <dependency> <groupId>io.rest-assured</groupId> <artifactId>xml-path</artifactId> <version>4.3.2</version> <scope>test</scope> </dependency> <dependency> <groupId>io.rest-assured</groupId> <artifactId>json-schema-validator</artifactId> <version>4.3.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-all</artifactId> <version>1.3</version> <scope>test</scope> </dependency> While working with cucumber framework, it is always recommended to have a different package for different cucumber components, this helps in developing a better project hierarchy and ease the process of understanding the test suite. Feature File: Reqres_api_test.feature Feature: Test Reqres user api’s with rest assured library and cucumber framework @SmokeTest Scenario Outline: Reqres GET API test Given the valid endpoint to fetch users When the request is send to server with page number as “<page>” Then validate the response of first user record having email as “<emailID>” Examples: |page|emailID | | 2 |michael.lawson@reqres.in| | 1 |george.bluth@reqres.in| @SmokeTest Scenario Outline: Reqres POST API test Given the valid endpoint with payload to create user When the request is send to the server Then the new user must be created with name as “<username>” Examples: |username| | john | With the above feature file, the goal is to perform parameterization testing with multiple test data. “Examples” keyword is used when test data has to be created and the test data is created with a pipe symbol as delimiter( | ). To add a parameter in a test step of a feature file, the syntax is “<variableName>”, the same has been used above. Further, the same variable name is used in the first row of Examples to segregate the test data according to specific parameters. Step Definition File: GetApiTest.java package stepDefinitions; import static io.restassured.RestAssured.given; import org.testng.Assert; import cucumber.api.java.en.Given; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; import io.restassured.RestAssured; import io.restassured.http.ContentType; import io.restassured.response.Response; public class GetApiTest { Response response; @Given("^the valid endpoint to fetch users$") public void setupEndpoint() { RestAssured.baseURI="https://reqres.in/"; RestAssured.basePath="/api/users"; } @When("^the request is send to server with page number as \"([^\"]*)\"$") public void sendRequest(int pageNumber) { response = given(). queryParam("page",pageNumber). when(). get(). then(). contentType(ContentType.JSON). extract().response(); } @Then("^validate the response of first user record having email as \"([^\"]*)\"$") public void validateUserData(String emailID) { String userEmail = response.path("data[0].email"); Assert.assertEquals(userEmail, emailID); } } PostApiTest.java package stepDefinitions; import static io.restassured.RestAssured.given; import java.util.HashMap; import org.testng.Assert; import cucumber.api.java.en.Given; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; import io.restassured.RestAssured; import io.restassured.http.ContentType; import io.restassured.response.Response; public class PostApiTest { Response response; public HashMap<Object,Object> map=new HashMap<Object,Object>(); @Given("^the valid endpoint with payload to create user$") public void setupEndpointAndPostData() { RestAssured.baseURI="https://reqres.in/"; RestAssured.basePath="/api/users"; map.put("name","john"); map.put("job", "Software Developer"); } @When("^the request is send to the server$") public void sendRequest() { response = given() .contentType(ContentType.JSON) .body(map) .when() .post() .then() .statusCode(201).contentType(ContentType.JSON). extract().response(); } @Then("^the new user must be created with name as \"([^\"]*)\"$") public void validateResponse(String name) { String userName = response.path("name"); Assert.assertEquals(userName, name); } } Above, we have created two step definition files as per 2 scenarios mentioned in the feature file, one for GET api validation and the other for POST api validation. In our step definition file, we have written an execution code for each test step defined in the feature file. This is the file that integrates rest assured with cucumber framework as all the api’s are being validated here. The test steps written in the feature file have to be the same in the annotated descriptions with the defined way of using parameters. Further, we have used a bit of TestNG here to assert the server response. Runner File: Runner.java package testRunner; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import cucumber.api.CucumberOptions; import cucumber.api.testng.CucumberFeatureWrapper; import cucumber.api.testng.TestNGCucumberRunner; @CucumberOptions( features = "src/test/java/FeatureFile", glue = {"stepDefinitions"}, tags = {"@SmokeTest"}, format = { "pretty", "html:target/cucumber-reports/cucumber-pretty", "json:target/cucumber-reports/CucumberTestReport.json", "rerun:target/cucumber-reports/rerun.txt" },plugin = "json:target/cucumber-reports/CucumberTestReport.json") public class Runner { private TestNGCucumberRunner testNGCucumberRunner; @BeforeClass public void setUp() throws Exception { testNGCucumberRunner = new TestNGCucumberRunner(Runner.class); } @Test(dataProvider="features") public void my_test(CucumberFeatureWrapper cucumberFeature) { testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature()); } @DataProvider public Object[][] features() { return testNGCucumberRunner.provideFeatures(); } @AfterClass public void tearDown() { testNGCucumberRunner.finish(); } } CODE WALKTHROUGH: In our cucumber test runner file, we have a CucumberOptions annotation that accepts parameters like path of the feature file and step definition file along with the tags name and reporting format along with HTML reporting plugin. To integrate Cucumber framework with Rest Assured Library and TestNG framework, we have used a cucumber framework predefined class called “TestNGCucumberRunner” which provides various methods such as runCucumber, provideFeatures, finish etc. “CucumberFeatureWrapper” is an interface used in a parameter of the Test annotated method for making TestNG report more descriptive. TestNG.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="TestNG-Cucumber Suite" thread-count="10" parallel="tests"> <test name="Apple test"> <classes> <class name="testRunner.Runner" /> </classes> </test> </suite> This is a TestNG xml file for configuring the execution of the test suite. We have used Runner java class to execute the api tests, once successfully executed, the report can be visualized from target directory -> cucumber-reports -> cucumber-pretty -> index.html. SHIVANI SINHA She is a Product Marketer with over 9 years of diversified experience across content, branding, and product marketing. Her experience ranges from global brands to nimble startups. She is a custodian of Brand & Content, telling stories about the brand that delights customers and provides compelling business value. Related Articles January 24, 2024 HOW TO GET STARTED WITH… Read more June 07, 2023 BEST UNIT TESTING FRAMEWORKS TO… Read more * Blog * Webinar * Video * Case Studies * Whitepaper * Academy COMPANY * About Us * Customer * Partners * News PRODUCT * No Code Test Builder * Easy Test Maintenance * Extended Test Coverage * Integrated Tests * In Built Test Management * Real Device Lab * Browser Labs * Test Analytics * Integrations * Rapid Automation Testing * Automation Execution * DevOps * Visual Testing * Self healing automation SOLUTIONS * Enterprise * Startups & SMB SUPPORT * Documentation * Pcloudy Certification * Contact Us RESOURCES * Blog * Webinar * Videos * Whitepaper Never miss an update Page URL Product Type * Copyright All Rights Reserved © 2024 * Terms of Service * Privacy Policy * News * Sitemap REQUEST A DEMO / PREMIUM ACCESS RELEASE DIGITAL APPS FASTER WITH CONFIDENCE LEARN HOW AI AUGMENTED UNIFIED APP TESTING SUITE CAN HELP YOU MOVE FROM LEGACY TESTING PRACTICES TO SCALE TESTING What to expect ? * 30 mins chat with our product specialist * Commitment free consultation on your top testing challenges * Showcase practical business use cases your whole team can use * How to use our AI stack to be future proof