Skip to content

Getting started

The examples call httpbin.org, which echoes back what you send.

  1. Make an empty folder and open it with Ctrl+O. cactus writes opencollection.yml. Add a base URL:

    opencollection.yml
    opencollection: "1.0.0"
    info:
    name: httpbin
    request:
    variables:
    - name: baseUrl
    value: https://httpbin.org
  2. Ctrl+N creates a request. Set the URL to {{baseUrl}}/anything?q=hello, send with Ctrl+Enter, and save with Ctrl+S.

    get-anything.yml
    info:
    name: Get anything
    type: http
    seq: 1
    http:
    method: GET
    url: "{{baseUrl}}/anything?q=hello"
    params:
    - name: q
    value: hello
    type: query
    auth: inherit
  3. On the Checks tab:

    get-anything.yml
    runtime:
    assertions:
    - expression: res.status
    operator: eq
    value: "200"
    - expression: res.body.args.q
    operator: eq
    value: hello
  4. Add auth/login.yml. Its action, on the Outputs tab, saves res.body.json.username as token:

    auth/login.yml
    info:
    name: Login
    type: http
    seq: 1
    http:
    method: POST
    url: "{{baseUrl}}/post"
    body:
    type: json
    data: |-
    { "username": "{{user}}" }
    runtime:
    actions:
    - type: set-variable
    phase: after-response
    selector:
    expression: res.body.json.username
    method: jsonq
    variable:
    name: token
    scope: runtime

    Use the token in get-anything.yml:

    http:
    auth:
    type: bearer
    token: "{{token}}"
  5. {{user}} isn’t set yet, so the response lists it as unresolved.

    environments/staging.yml
    name: staging
    variables:
    - name: user
    value: staging-bot
    - name: password
    secret: true

    Pick staging in the sidebar. Enter the password value under Variables (Ctrl+E). Secret values are stored in .cactus/, which git ignores.

  6. Ctrl+B opens Critters. Add a critter bot with a flow smoke:

    critters/bot/flows/smoke.yml
    name: Smoke test
    steps:
    - request: auth/login.yml
    - request: get-anything.yml
    expect: 200
    assert:
    - expression: res.body.headers.Authorization
    operator: eq
    value: Bearer staging-bot

    Click Run.

  7. Terminal window
    cactus-cli flow . bot smoke -e staging
    bot › smoke
    ✓ 200 312ms 1. Login auth/login.yml
    ✓ 200 280ms 2. Get anything get-anything.yml
    1/1 flow passed

    Exit code 0 means everything passed and 1 means something failed.