Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing variable from response to request in JMETER

Tags:

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

like image 805
user299702 Avatar asked Jan 14 '16 13:01

user299702


2 Answers

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
like image 111
Dmitri T Avatar answered Nov 10 '22 12:11

Dmitri T


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

like image 44
alphamikevictor Avatar answered Nov 10 '22 13:11

alphamikevictor