1.0.18 • Published 4 years ago

testapis v1.0.18

Weekly downloads
22
License
ISC
Repository
-
Last release
4 years ago

api-testing-doc

Quick unit test and export document APIs

Features

  1. Test REST APIs base on scenario files
  2. Validate response data, response headers...
  3. Re-use variable after each steps
  4. Split a big testcases to many smaller testcases which make easy testing for large project
  5. Easy to extends for specific project

How to use

Installation

npm install -g api-testing-doc

Write testcase

  • Main scenario file must be index.yaml

Run test

api-testing-doc \"$PWD/$PATH_OF_SCENARIO_FILE/index.yaml\"

How to write a testcase

  1. Main testcase file index.yaml which is used to execute the first
...: !include $YAML_SHARE_VARIABLE # Auto merge data in $YAML_SHARE_VARIABLE
title: Test APIs                    # Project name
description: Demo APIs              # Project description
version: 2.0.0                      # API Version
saveTo:                             # Where API Document will be saved to
  md: ./output/abc.api.user.v2.0-client.md  # Save to MD format
  swagger: ./output/abc.api.user.v2.0-client.yaml # Save to swagger (open api) format
endpoints:                          # Base URL of APIs which is showed on API Document
  - url: http://localhost:3000
    description: development
  - url: https://staging-api.abc.vn/relation/v2.0
    description: abc/staging
style: doc                          # How to display on screen (doc, test, summary)
vars:                               # Declare variables which is used in the running progress
  url: http://localhost:3000          # Example: Use ${url} in context
  pj: test-project                    # Example: Use ${pj}
  user:                               # Example: Use ${user} in context
    name: thanh                       # Example: Use ${user.name} in context
    pwd: passhere                     # Example: Use ${user.pwd} in context
templates: 
  - $api key=base:
    headers:
      app: test-app
    extra01: ignore it when extends
    extra02: keep it when extends
steps:
  - $api: Login
    key: login                              # Declare key for others copy its properties
    extends:                                # Copy properties from another
      key: base                               # Copy properties from a API which got key is "base"
      omit:                                 # Default no omit
        - extra01                             # Remove "extra01" when extends from "base"
      pick:                                 # Default pick all
        - extra02                             # Only take "extra02" when extends from "base"
    vars:                                   # Declare variable before run this API
      myvar: 10
    method: GET                             # Http method (GET, POST, PUT, PATCH, HEAD, DELETE)
    baseURL: ${url}                         # Base url (Example: http://localhost)
    url: /login?page=:PAGE&recordsPerPage=:ITEMS_PER_PAGE&myVar=:MY_VAR
    headers:                                # Request header
      project: ${pj}          
    query:                                  # Request query string
      PAGE: 1                                 # Can use "page" or "PAGE" are same
      recordsPerPage: 20                      # Can use "recordsPerPage" or "ITEMS_PER_PAGE" are same
      MY_VAR: ${myvar}                        # Use in "vars"
    body:                                   # Request body
      ...: ${user}                            # Same {...user} in javascript
      display_name: ${user.name}              # body object is {name: "thanh", pwd: "passhere", display_name: "thanh"}
    var: me                                 # Response data will store at "me" variable ${me}
  # var:                                    # Response will store at some variables
    #   token: ${$.response.headers.token}    # ${token} = token value in response header
    #   me: ${$.response.data}                #  ${me} = respones data
  - $echo: Print some thing here ${me}        # Show some messages (${me} content)
  
  - !include $YAML_FILE_HERE            # Import external yaml file which includes steps

  - $pause: Pause 5s then keep running  
    time: 5000
  - $pause time=5000: Pause 5s then keep running
  - $pause: Pause & Enter to keep running

  - $vars: Update user data                   # Set or merge variable
    set:                                      # Replace variable
      user.name: test                         
    merge:                                    # Merge data
      user:
        age: 32

  # Note: $api, $echo, $group, !include, $pause... are called be steps
  
  - $group: Group some steps to make the tracking to be easier
    vars:
      my_var_in_group:  10                  # Declare variables which are used before run this group
    steps:
      - $echo Hello ${my_var_in_group}
      # ...steps here
docs:
  swagger: # Swagger open api format. Refer: https://swagger.io/specification/
  md:
    note: # Some notes which is append in md document file
  1. Steps which are used in context
  • $api: Make http request
  • $echo: Print message on console screen
  • $pause [time]: Pause the progress. If there is no time value (ms) is filled, it will be paused forever)
  • $group: Group steps
  • $vars: Set or merge variable
1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago