Crash Course: API Testing with RapidAPI & GitHub Actions

APIs are ubiquitous. When you have shift-left approach, API testing is critical. There are umpteen tools and solutions out there in the market. But in this blog, we are going to see how you can get started with RapidAPI. What makes RapidAPI is unique from other tools? Particularly we are going to see about API Testing with RapidAPI Testing and its GitHub Actions.

What is RapidAPI?

RapidAPI started back in 2015 from a hackathon. It is a one-stop shop for APIs and developed for developers, by developers.

Suppose if you are developing a web application, and you want to implement third-party feature such as weather, trivia, movie ratings etc. Just head to RapidAPI marketplace, search using the keyword, select the API based on its popularity, latency, and service level, then subscribe to it, copy the snippet and embed the code into your app.

RapidAPI Offerings

RapidAPI has multiple offerings. Starting point would be the marketplace where you can search, explore, evaluate the APIs from hundreds of providers.

If you need team features such as sharing, collaboration etc, then RapidAPI for Teams enables them.

For enterprise features such as private workspace, access control, CI/CD features etc, then you can opt for Enterprise Hub.

To test the APIs, RapidAPI Testing enables to create tests, execute, schedule, monitoring, reporting and more.

To accelerate API delivery, streamline collaboration, you have got RapidAPI Design by Paw.

  • RapidAPI Marketplace
    • Search API
    • Integrate
  • RapidAPI for Teams
    • Share
    • Collaborate
  • RapidAPI Enterprise Hub
    • white-labeled marketplace
    • developers, customers, and partners
  • RapidAPI Testing
    • testing
    • performance monitoring
  • RapidAPI Design
    • API design

Let us dive into RapidAPI Testing.

Getting Started with RapidAPI Testing

Head to rapidapi.com to sign up for a free account. After successful login, click on My APIs in the top right.

API Testing with RapidAPI Testing - My APIs
API Testing with RapidAPI Testing – My APIs

In the provider dashboard, click on Add New API to create an API, and fill-in the mandatory fields as shown below. You can upload your API specs using the UI, OpenAPI, Postman Collection, GraphQL Schema and Kafka.

After specifying the API, click on Add API button. In the below example, let us create an API using GraphQL Schema called Northwind.

Add API
Add API

Once the API is created, you can check out the graphql endpoint in API Specs page in Definitions. To create a test suite, click on Testing tab which will open the RapidAPI Testing in a new tab.

Endpoints
Endpoints

Creating a Test suite

Click on Create Test button to create a test for Northwind API. Enter a valid name and then click on OK.

Create Test
Create Test

There are multiple ways to create a test:

  1. manually adding steps
  2. request generator
  3. code

Let us take an easy path to create our simple test using the Request Generator. Follow the steps mentioned in the below screenshot.

Add to Test
Add to Test

In the body section, you can enter the below query for testing.

query {
  viewer {
    category {
      categoryID
    }

    product {
      name
    }
  }
}

Validating the request

Click on Send button to validate the response. To add this request to the suite, click on Add to Test button in the bottom right corner.

In Add Request to Test dialog, you can configure the variable name and other assertions as shown below.

Add Request to Test
Add Request to Test

Let us go with all the assertions, then click on OK, to add it to the test suite.

Testing the suite

To save and run, click on Save & Run button as shown below.

Save & Run
Save & Run

Click on the Recent Results item to view the results.

Test Report
Test Report

Here is the result:

Execution Report
Execution Report

In the report, you can see the details like ID, environment, location, execution time, and the detailed request and response details for each step.

To add the test variables, click on Settings.

To schedule the test, click on Schedule.

To view the analytics, click on Analytics.

To view the performance, click on Performance in the left menu. The larger the bubble, higher the latency.

Performance
Performance

GitHub Actions

RapidAPI has a free GitHub Actions which will help you to run your tests in GitHub servers. To add the RapidAPI action, go to this repo.

To make use of RapidAPI action in GitHub, let us create a new repository in GitHub. Click on Actions > New Workflow.

Create a workflow
Create a workflow

Then click on set up a workflow yourself link.

Set up workflow
Set up workflow

Delete the default yml content and paste the below yml.

on: [push]

jobs:
  run_api_test:
    runs-on: ubuntu-latest
    name: Execute RapidAPI API Tests
    steps:
    - name: Execute Tests
      id: tstExec
      uses: RapidAPI/[email protected]
      with:
        test: 'YOUR_TEST_ID'
        location: 'AWS-US-WEST-2'
        environment: 'ENV_ID(OPTIONAL)'
    - name: Show Results
      run: echo "The test took ${{ steps.tstExec.outputs.time }}ms to run"; echo "The test result was ${{ steps.tstExec.outputs.computedStatus }}"; echo "View Report - ${{ steps.tstExec.outputs.reportUrl }}"

In the above yml, you need to add your test id. To grab the test id, go to your test suite in RapidAPI Testing, take it from the URL query parameter test=.

After configuring the yml, click on Start Commit > Commit changes. This will start the workflow in the Actions.

Click on Actions, and navigate to your workflow and expand Show Results section as shown below to view the report link.

Click on the report link to view the results.

GitHub Actions Results
GitHub Actions Results

RapidAPI Testing features

RapidAPI Testing supports advanced tests such as chaining, conditional statements, looping, JWT, database connections, Faker library etc. For the help docs, please visit the official doc.

Conclusion

Using RapidAPI Testing, you can seamlessly integrate your test suites with the developers environment. It also supports multiple integrations, alerts, environments, and test variables.

By leveraging the performance and analytics dashboard, API monitoring helps to deliver the API quickly.

API Testing with RapidAPI Testing

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Join the fastest growing Performance Engineers club at ClubhouseSHOW ME HOW
+ +
Share via
Copy link