Executing from Cucumber

Cucumber is the most common behavior-driven development language for testers. This perfectly dovetails with the capabilities of API Fortress, as both are focused on making testing more intelligent and powerful without adding complication. The Cucumber tool, combined with API Fortress, is a great method of creating smart tests easily.

With the flexibility of the API Fortress, you can easily invoke API Fortress tests within your Cucumber Automation Scripts. Simply make an HTTP request to our webhook to kick off a test from your Cucumber test. Have a link to the report printed out into your console, or print the results directly on the console.

Below, we will show you how to easily integrate an API test into your Cucumber scripts.

You can find an example script on out Github.

First lets walk through the files and method used in the example:

  1. config.jsonThis is where you fill configure your API Fortress Project names and their associated webhooks. This allows you to invoke the tests by simply passing the Project name in the feature file.
  2. apifun.featureThis is where you define the scenario and the steps using the Gherkin syntax. In this file you will define the Given, When, Then steps. In this example we pass in an API Fortress Project name in the “Given” step.
  3. Stepdefs.javaIn this example we are using Java, however Cucumber supports many programming languages. The example file contains a few things:
    1. Stepdefs class
      1. In this class you will define what happens in each step from your feature file (Given, When, Then)
      2. Given – will take in the inputed Api Fortress Project name and call the getProjInfo method to get the webhook for this project
      3. When – will take the url of the webhook and call the callAPI method running all the API Fortress tests contained within that project
      4. Then – will parse through the response of the API Fortress webhook to provide the amount of failures, links to the API Fortress test results, and will indicate which tests passed and which failed
    2. getProjInfo methodThis method will parse the config.json file and match the Project name provided in the Given step to the Project name defined in the config file. This method will then return the associated webhook.
    3. callAPI methodThis method will take the webhook url from the When step and make a call to the API running all API Fortress tests within that project. This method will return the response from the API.