Zsolt Szilagyi
Zsolt Szilagyi

Reputation: 5006

jMeter: How to save a variable as cookie

I'm testing a site in jMeter 5.1 that once returns a header "X-Csrf-Token" and expects the value to be found in a cookie named __csrf_token-1.

The HTTP Cookie manager alone is no help, as I need to write a response header (not a recieved cookie) into a cookie.

How can change cookie values on the fly?

Thanks!

Upvotes: 0

Views: 1342

Answers (1)

Dmitri T
Dmitri T

Reputation: 168002

  1. Extract the cookie from the previous response using i.e. Regular Expression Extractor configured like:

    enter image description here

    double check that the extraction succeeds using Debug Sampler and View Results Tree listener combination

  2. Add HTTP Cookie Manager as a child of the next request and configure it to send __csrf_token-1 cookie with the value of ${token}

    enter image description here

    make sure to provide correct Domain and Path values, if you don't know them - change "Cookie Policy" to netscape

Upvotes: 1

Related Questions