Search This Blog

Breaking

Tuesday, 16 March 2021

API Automation with restQA tool

Recently, I came across a new open-source tool restQA which is available now for API Automation. 

I found this tool very useful and easy to adopt. The good thing with this tool is that it gives a true flavor of BDD

In API Automation. Practically, with this tool, We can start writing our automation parallel with API development, and even BA's and PO's can also contribute to writing feature files.


Let me briefly explain some of the features which I liked about the tool:


  1. Plain English-like syntax for API requests makes API Automation scenarios more readable. Anyone can now write and understand the API automation from the feature file.
  2. Support of 50+ already implemented step definitions
  3. Very quick to install and quick to use
  4.  Easy integration with other plugins like Jenkin, slack, etc
  5.  Inbuilt reporting


Though the tool is still evolving, and it might be that you will see some crucial steps missing, still it gives hope to use an open-source BDD tool in API Automation.


Let me share my experience with the tool while automating a simple CRUD scenario:


Software Required:

  • NodeJs 
  • Npm or Yarn 

Steps Followed:

1. Install NodeJS and NPM in machine. In My machine, I already have this softwares. So I just corss checked. :)

deepakmathpal@Deepaks-MacBook-Air restqaTest % node --version

v12.18.3


deepakmathpal@Deepaks-MacBook-Air restqaTest % npm -version

6.14.6


2. Created a folder and inside that, installed the project with the below command (globally):


npm install @restqa/restqa -g


3. Initialize your first project:


restqa init -y



That's It !! The project is ready to use now. You can now import this folder into your Visual studio code. 

And now you can start writing your own feature file with the help of predefined steps:


You can get all the predefined implemented steps with the help of the below commands:


restqa steps given

restqa steps when

restqa steps then







 


Now, you can start automating your use cases.


Feature: Validate CRUD Behaviour


Background: 

Given I have the api gateway hosted on "https://jsonplaceholder.typicode.com"


Scenario: Get all post

  And I have the path "posts"

  And I have the method "GET"

  When I run the API

  Then the response time is under 1000 ms


  Scenario: create a new post

    And I have the path "posts"

    And the payload: 

    """

    {"title":"foo","body":"bar","userId":1}


    """

    And I have the method "POST"

    When I run the API

    Then I print the request

    And I print the response

    And I should receive a response with the status 201

    And the response should not be empty array  

    And the response body at "userId" should equal 1

    And the response body at "title" should equal "foo"

    And the response body at "body" should equal "bar"

    And the response body at "id" should equal 101 








Once the scenario is complete, you can run all your feature file scenarios:

restqa run 

The execution will start, and a report link will generate at the end of the execution.





When you open the link, a report comes like this:










If you want to run only your feature file scenario, you can run it with the below command:

restqa run tests/integration/CRUDScenario.feature 

Your report will now show only specified feature file scenarios:










That's it for now. I will keep updating when I will see more features from this project.

More detail of the project can be found from: https://docs.restqa.io/

Till then Happy Learning.

No comments:

Post a Comment