Instant Testing of RESTful API with BDDfire and Cucumber

BDDfire2.0.1 + REST API Testing

Glad to announce support for the API testing to BDDfire as we can now use pre-defined steps to perform API testing using combination of Cucumber and RestClientBDDFire is a wholesale Ruby-Cucumber framework where you can setup Web, Mobile, Accessibility, Load, Performance and now REST API testing.

BDDfire  + RestClient

BDDfire uses RestClient to perform HTTP requests to URI and check response. We can use it for checking JSON and XML response.

There are following pre-defined steps we can use to check JSON response.

   Given I send a GET request for "<your_uri>"

   Given I send a GET/PUT/POST/DELETE request for "<your_uri>" with the following: 
    """
   <your_payload>
    """

   Then the response should be JSON

   Then the response status code should be '200'

   Then the JSON response should have '<number_of_properties>' properties

   Then the JSON response has a "<id_of_property>" property

   Then the JSON "<id_of_property>" property equals "<value_of_property>" 

   Then the JSON response header has key "<header_name>" with value of "<header_name>" 

   Then /^the JSON response should be:
    """
     <your_json>
    """

 

There are few to check XML response as well

Given I send a GET request for ""

Then the XML response should have "" with text ""

Then the response status code should be '200'

 

Here is how you can get API tests up and running in few minutes with BDDfire. Fire up your terminal/iTerm and execute following commands to get the project setup

$ gem install bddfire 
$ bddfire fire_cucumber
$ cd cucumber 
$ bundle install

Now that you have all the project setup and you should have project like this :

bddfire_project

 

You can see that there is a example feature located ‘features/api.feature’ which tests for the GitHub Api. We can write a similar cucumber scenarios/steps for our own application. Now we can run to run this api tests.

$ bundle exec rake api

Here is how we can execute our REST API test

api

 Additional Config

On top of pre-defined API Steps, you can use full power of RestClient  to configure your API environment with

  • Certificates
  • Proxy
  • Username and Password Credentials.

Please have a look at README file for the RestClient and we can achieve anything we want.

Additionally, I haven’t tested XML response well so feel free to create issue on BDDfire GitHub

https://github.com/Shashikant86/bddfire

 

HAPPY BDD and HAPPY RESTFul Testing !!