user299702
user299702

Reputation: 825

Passing variable from response to request in JMETER

In need to pass a data from a response to the subsequent request. Something goes wrong and the default variable value appears in the request.

First request returns the JSON in response body which looks like this:

{"issued_at":"2016-01-14T12:41:01.000Z","expires":"2016-01-14T12:46:01.000Z","id":"j6M ... MTA=="}
enter image description here

I extract the value of the id attribute using the Regular Expression Extractor:

enter image description here

Then I pass the token variable to the subsequent request parameter:

enter image description here

But the request is created with the default value of the variable:
enter image description here

Upvotes: 18

Views: 41440

Answers (4)

Steve
Steve

Reputation: 4655

You should use ${token_g1} to get the value of the first group of the regex match (the value you're looking for).

Upvotes: 0

user299702
user299702

Reputation: 825

The problem was resolved by setting the "Field to check" radio button to "Body" at the "Regular Expression Extractor" dialog and by setting the Template field value to $1$. Thanks to alphamikevictor and Dmitri T for help!

Upvotes: 2

Dmitri T
Dmitri T

Reputation: 168147

There is a JSON Path Extractor designed to deal with JSON content type, I believe it would be easier to use it.

The relevant JSON Path query will be as simple as $..id

See Using the XPath Extractor in JMeter (scroll down to "Parsing JSON") for comprehensive information on plugin installation and usage and JSONPath - XPath for JSON for JSONPath language reference and examples.

In regards to your Regular Expression Extractor configuration:

  • remove 1 from Match No.
  • Provide $1$ as Template

Upvotes: 10

alphamikevictor
alphamikevictor

Reputation: 647

If you look at the Regular Expression Extractor documentation, the field Template is required. I suggest you to use value $1$ and try again.

Upvotes: 3

Related Questions