API automation using Blazemeter | HCLTech
Engineering

API automation using Blazemeter

Blazemeter facilitates rapid API test creating and monitoring from the initial stages of software development to supporting a shift-right continuous testing strategy.
 
5 minutes read
Aakash Vijayvergiya

Author

Aakash Vijayvergiya
Technical Lead
5 minutes read
Share
blazemeter

What is API automation and why Blazemeter?

testing involves evaluating the functionality, reliability, performance and security of an API. As APIs connect different software systems, enabling them to communicate and share data, testing ensures they operate seamlessly and handle various scenarios, making it a crucial aspect of software development and maintenance.

Blazemeter facilitates rapid API test creating and monitoring from the initial stages of development to production. It integrates smoothly with open-source and third-party tools like Jenkins, Slack and more, providing timely notifications to the relevant teams in case of API issues. Additionally, Blazemeter API Monitoring can be combined with performance and load testing to conduct comprehensive stress tests on APIs, supporting a shift-right continuous testing strategy.

Advantages of API automation:

  • Efficiency and speed: Automated tests run more quickly and efficiently than manual tests
  • Reusability: Automated API tests can be reused throughout different development stages and environments
  • Consistency: Automated tests provide consistent and repeatable results, crucial for ensuring that API changes do not introduce unexpected issues
  • Regression testing: Automated API testing is particularly valuable for regression testing
  • Early defects detection: The API test suite could be integrated into the CI/CD pipeline to discover defects early in the development cycle
  • Cost-effective: involves some initial development cost, but long-term it helps in cost savings by automating repetitive tasks and validations

Automating APIs in Blazemeter

  1. Create a new workspace in Blazemeter and then click on Create Test dropdown to create your first API automation test.

    It has 2 options: New Test and Import Test

    1. New Test: To create a new API automation script from scratch
    2. Import Test: To import an existing API test from an external source, be it an existing Blazemeter script or Postman or from any other API automation source.

    Automating APIs in Blazemeter

  2. Post clicking New Test, the user will get the below screen where he or she can start writing their API automation test.

    Post clicking New Test

    1. First, select the request type (GET, POST, PUT, PATCH, DELETE, etc.) and provide the URI for the API that needs to be triggered.

      First

      (Note: We can select the type of authentication (Basic Auth, OAuth 1.0, OAuth 2.0, etc.) that is required while hitting the URL/API for validation)

    2. Users can pass the request headers and query parameters from the section highlighted in the screenshot below.

      First

    3. Then, the user can add the Assertions from the Assertions tab to validate the response code and return the results. The following are the Assertion options to validate the expected results.

      validate

    4. If the user needs to reuse any value from the response result JSON, then they can extract the JSON response Key and add it to a script-level variable that can be reused in subsequent steps.

      Sample snippet for response JSON:

      {"employees":[  { "firstName":"John", "lastName":"Doe" },  { "firstName":"Anna", "lastName":"Smith" },  { "firstName":"Peter", "lastName":"Jones" } ]}

      To extract firstName “John” from the above response JSON, the user can add the variable property as employees[0].firstName

      Sample snippet for response JSON

    5. We have the option to add more conditions and include subtests based on the result of the previous Step.

      Ex: The user can use the extracted Variable to in a new condition to depend on the next subtest step to be executed. The same can be seen in the below screenshots.

      employees

      Add Shared Environment

      (Note: Create a shared environment from “Add Shared Environment” and provide the initial variables like the API URL to be triggered, login username, Password, etc. Users can also define authentication, headers, etc., while setting up the Shared Environment to be reused in API execution.)

    6. Save and Run

      Congratulations! You just created and executed your first API automation test with Blazemeter.

    References

    https://www.blazemeter.com/product/blazemeter/api-monitoring

    https://www.w3schools.com/

    https://www.runscope.com/

Share On