Home » Software Testing » API Testing with Cucumber, The Most Popular BDD Framework

API Testing with Cucumber, The Most Popular BDD Framework

API testing with Cucumber is really innovative way of using BDD style feature file. cucumber-api lets one validate public APIs JSON response in blazingly fast time.

Inspired by cucumber-api-steps.

Checkout sample to see cucumber-api in action.


Add cucumber-api gem to your Gemfile:

Require cucumber-api in your Cucumber’s env.rb:


Verbose logging: enable verbose logging of API calls and responses by settingcucumber_api_verbose=true in your ENV, preferably via your cucumber.yml


Available steps

Preparation steps

Specify your request header’s Content-Type and Accept. The only supported option for Accept isapplication/json at the moment.

Specify POST body

Or from YAML/JSON file


Request steps

Specify query string parameters and send an HTTP request to given URL with parameters

Temporarily save values from the last request to use in the next request in the same scenario:

The saved value can then be used to replace {placeholder} in the next request.


Assume that http://example.com/token have an element {"request_token": 1, "access_type": "full"}, cucumber-api will execute the followings:

This will be handy when one needs to make a sequence of calls to authenticate/authorize API access.

Assert steps


  • HTTP response status code
  • JSON response against a JSON schema conforming to JSON Schema Draft 4
  • Adhoc JSON response key-value type pair, where key is a JSON path


Also checkout sample for real examples. Run sample with the following command:

Response caching

Response caching is provided for GET requests by default. This is useful when you have a Scenario Outline or multiple Scenarios that make GET requests to the same endpoint.

Only the first request to that endpoint is made, subsequent requests will use cached response. Response caching is only available for GET method.


Read Similar Posts

Leave a Reply

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

Scroll to Top