Capture Response Usage

The capture block stores the full HTTP response into a variable so that later requests, conditions, and assertions can reuse it.

Basic Syntax

httpRequest:
  capture:
    to: VariableName
    as: Json|QJson|String|QString|Xml|QXml|Csv|QCsv|Int|Double|Boolean
    regex: "optional-regex"
    makeGlobal: false

What Gets Captured

When a response is captured, the variable exposes:

  • Body
  • StatusCode
  • StatusReason
  • Headers.<HeaderName>

Examples:

${LoginResponse.Body}
${LoginResponse.Body.token}
${LoginResponse.StatusCode}
${LoginResponse.StatusReason}
${LoginResponse.Headers.Content-Type}
${LoginResponse.Headers.Set-Cookie[0]}

Choosing as

  • Json / QJson for JSON response bodies
  • Xml / QXml for XML response bodies
  • Csv / QCsv for CSV response bodies
  • String / QString for raw text responses

Use the quoted Q* forms when a quoted string is more convenient in expressions.

Example: Capture Users Response

name: TestPlan
rounds:
  - name: FeatureRound
    numberOfClients: 10
    arrivalDelay: 1000
    runInParallel: false
    iterations:
      - name: users
        httpRequest:
          capture:
            to: users
            as: Json
            makeGlobal: true
          url: https://jsonplaceholder.typicode.com/users
          method: GET

After this request, you can access values such as:

${users.StatusCode}
${users.Body[0].id}
${users.Body[$length($users.Body)-1].id}

Arithmetic Expressions in Captured Values

Captured values support arithmetic expressions where indexes are used:

  • JSON: ${users.Body[0+1].id}
  • XML: ${catalog.Body/items/item[1+1]/name}
  • CSV: ${sheet.Body[0+1,1]}
Notes:
  • JSON and CSV indexes are zero-based.
  • XML follows XPath semantics, so positions are one-based.
  • Non-arithmetic selectors remain unchanged.

Scope

  • Captured variables are session-scoped by default.
  • Set makeGlobal: true when later rounds or other sessions need the same captured value.