Home » Software Testing » Automation Testing » Calabash » API Testing in BDD style with Cucumber

API Testing in BDD style with Cucumber

API testing in BBD style with Cucumber. 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.

Installation

Add cucumber-api gem to your Gemfile:

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

Configuration

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

Usage

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

Example:

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.

Example:

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

Verify:

  • 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

Example:

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.

Dependencies

Read Similar Posts



Leave a Reply

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