# Correlation: extract values from earlier responses (regex, CSS selector,
# JSONPath, headers, boundary) and reuse them in later requests.
name: correlation
description: extract CSRF + session values and chain requests

defaults:
  http:
    base_url: https://shop.example.com

scenarios:
  checkout:
    executor: constant-vus
    vus: 3
    duration: 1m
    flow:
      - request:
          name: form page
          url: /checkout/start
          extract:
            # CSRF token hidden in the HTML form
            - { type: css, name: csrf, expression: "input[name=csrf]", attribute: value }
            # The same, JMeter-boundary style (first match wins; default if absent)
            - { type: boundary, name: trace_id, left: 'data-trace="', right: '"', default: none }
            # A response header
            - { type: header, name: request_id, header: X-Request-Id }
      - request:
          name: submit
          method: POST
          url: /checkout/submit
          headers:
            X-Parent-Request: ${request_id}
          body:
            form:
              csrf: ${csrf}
              trace: ${trace_id}
          extract:
            - { type: jsonpath, name: order_id, expression: "$.order.id" }
          assert:
            - { type: status, equals: 200 }
      - request:
          name: order status
          url: /orders/${order_id}
          checks:
            - { type: jsonpath, name: order is pending, expression: "$.status", equals: pending }
