Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Latest commit

 

History

History
369 lines (287 loc) · 8.01 KB

SCHEMA.md

File metadata and controls

369 lines (287 loc) · 8.01 KB

How to write Test? The Schema

version Required

Property specifying the version of the schema. Available versions:

  • 2

variables

You can define custom variables to use them later in a request. They work across files, so you can define them in one file and use them in an other.

# Example
variables:
  example_url: https://jsonplaceholder.typicode.com/todos/1
  example_id: 1

requests:
  test:
    request:
      url: <$ example_url $>
      ...

allowInsecure

Boolean to allow:

  • insecure certificates
  • self-signed certificates
  • expired certificates
# Example
allowInsecure: true
someRequest:
  request:
    url: ...
    method: ...

requests Required

Array which holds all the requests that are going to be tested

# Example
requests:
  request1:
    ..
  request2:
    ..
  request1000:
    ..

requestName At least one request is required

A single request. You can name the request however you want. Try not to overwrite names because this will also overwrite the response data and you'll no longer be able to retrieve the data from the overwritten request.

# Example
requests:
  someRequestName: # <- a Request
    ..

if

This provides conditional execution of a request.

version: 2

requests:
  if_Set:
    request:
      url: https://jsonplaceholder.typicode.com/posts
      method: POST
      postData:
        mimeType: application/json
        text:
          foo: 1
  skipped:
    if:
      operand: <$ if_Set.content.foo $>
      equals: 2
    request:
      url: https://jsonplaceholder.typicode.com/todos/2
      method: GET
  executed:
    if:
      operand: <$ if_Set.content.foo $>
      equals: 1
    request:
      url: https://jsonplaceholder.typicode.com/todos/2
      method: GET

delay

If present, the execution of the request will be delayed by the specified number of milliseconds.

# Example
someRequest:
  delay: 2000 # Wait 2 seconds before perfoming request
  request:
    url: ...
    method: ...

request Required

The request object conforms with HAR

url Required

The target URL to which the request will be sent to. Needs to start with http or https

# Basic Example
someRequestName:
  url: http://localhost:3000/api

# Example with a connected value
someConnectedRequest:
  url: http://localhost:3000/api/user/Value(getUser.id)/friends
method Required

The HTTP request method that will be used Strest to perform the request. All strings are accepted but consider to use one of the requests listed in the Mozilla Developer Docs

# Example
somePostRequest:
  request:
    url: ...
    method: POST
postData

Follows this schema.

mimeType

Set the mimeType to:

  • application/json
  • plain/text
text
# JSON Example
version: 2

requests:
  postRequest:
    request:
      url: https://postman-echo.com/post
      method: POST
      postData:
        mimeType: application/json # Set the mimeType
        text:
          foo:
            bar: "baz"
# Raw Data Example
version: 2

requests:
  postRequest:
    request:
      url: https://postman-echo.com/post
      method: POST
      postData:
        mimeType: text/plain  # Set the mimeType
        text: "This is raw text"
queryString

Conforms to this shema. Formatted as an Array.

version: 2

requests:
  responseHeaders:
    request:
      url: https://postman-echo.com/response-headers
      method: GET
      queryString:
      - name: foo1
        value: bar1
      - name: foo2
        value: bar2
headers

Specify HTTP headers that you want to be sent with the request. Formatted as an Array.

# Basic Example
version: 2

requests:
  requestHeaders:
    request:
      url: https://postman-echo.com/headers
      method: GET
      headers:
        - name: exampleHeader
          value: "Lorem ipsum dolor sit amet"
    validate:
      - jsonpath: content.headers.exampleheader
        expect: "Lorem ipsum dolor sit amet"
  requestHeaders2:
    request:
      url: https://postman-echo.com/headers
      method: GET
      headers:
        [{ "name": "h1", "value": "v1" }, { "name": "h2", "value": "v2" }]
    validate:
      - jsonpath: content.headers.h1
        expect: "v1"
      - jsonpath: content.headers.h2
        expect: "v2"

auth

Predefined authentication methods which will set the Authorization header automatically

basic

HTTP Basic Authentication. Requires username and password.

# Example
someRequest:
  request:
  ...
  auth:
    basic:
      username: myusername
      password: test123

validate

The immediate response is stored in HAR Format

With Strest you can validate responses with:

Read jsonpath for more info and see this file for more complex example

jsonpath required

Read jsonpath for more info and see this file for more complex example

Expect
requests:
  example:
    ...
    validate:
    - jsonpath: content
      expect: "the response has to match this string exactly"
Type
version: 2

requests:
  typeValidate:
    request:
      url: https://jsonplaceholder.typicode.com/todos
      method: GET
    validate:
    - jsonpath: headers["content-type"]
      type: [ string ]
    - jsonpath: status
      type: [ boolean, string, number ]
    - jsonpath: content.0.userId
      type: [ number ]
Regex

Regex can be used to validate status code or any other returned param

version: 2

requests:
  codeValidate:
    request:
      url: https://jsonplaceholder.typicode.com/todos
      method: GET
    validate: # Multiple ways to use regex to validate status code
    - jsonpath: status
      regex: 2\d+
    - jsonpath: status
      regex: 2[0-9]{2}
    - jsonpath: status
      regex: 2..
    - jsonpath: status
      regex: 2.*

Read jsonpath for more info and see this file for more complex example

log

If set to true, the following information will be logged into the console for this request. HAR

  • Response Status
  • Response Text
  • Response Headers
  • Response Content

If you want to log information of all requests into the console, use the -p flag when using the strest command