Skip to content

Boilerplate project to run REST API tests with Cucumber & Pactum

License

Notifications You must be signed in to change notification settings

pactumjs/pactum-cucumber-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pactum-cucumber-boilerplate

Boilerplate project to run REST API tests with Cucumber and PactumJS

Setup

There are 2 options to setup this project:

  • Manually clone this project then install all dependencies
  • Simply using pusakatest CLI tool
    • If you don't have a package.json in your file directory, it will be copied from one of the templates available at pusakatest when you run below command
    • If you already have a package.json file, add all the dependencies mentioned in pusakatest to your package.json (below command will not override or replace your package.json file)
npx pusakatest

Sample Test Case

Feature: Regres

  In order to keep Regres api stable
  As a tester
  I want to make sure that everything works as expected
  
  Scenario: Get A User With Id
    Given I make a GET request to /api/users/{id}
      And I set path param id to $S{UserId}
     When I receive a response
     Then I expect response should have a status 200
      And I expect response should have a json like
      """
      {
        "data": {
          "id": 7
        }
      }
      """

Running Tests

npm run test

Gherkin Expressions

Sample Step Definitions

  Given
    I make a (.*) request to (.*)
    I set path param (.*) to (.*)
    I set query param (.*) to (.*)
    I set header (.*) to (.*)
    I set cookie (.*) to (.*)
    I set basic authentication credentials (.*) and (.*)
    I set body to
    I set multipart form data (.*) to (.*)
    I upload file at (.*)
    I set form-data to
    I set inspection
  
  When
    I receive a response
  
  Then
    I expect response should have a status {int}
    I expect response header (.*) should be (.*)
    I expect response header (.*) should have (.*)
    I expect response cookie (.*) should be (.*)
    I expect response should have a json
    I expect response should have a json at (.*)
    I expect response should have a json like
    I expect response should have a json like at (.*)
    I expect response should have a json schema
    I expect response should have a json schema at (.*)
    I expect response should have a body
    I expect response to match a json snapshot (.*)
    I expect response body should contain (.*)
    I expect response should have {string}
    I expect response time should be less than {int} ms
    I store response at (.*) as (.*)