Reputation: 51
how to extract JSON path and find array length using java? for my below response data. I need to validate array length should be equal to '7' in Jmeter assertion.
[
[
"Week",
"Event Count"
],
[
"3/13/17",
"1"
],
[
"3/20/17",
"1"
],
[
"3/27/17",
"1"
],
[
"4/3/17",
"1"
],
[
"4/10/17",
"1"
],
[
"4/17/17",
"1"
]
]
Upvotes: 4
Views: 5376
Reputation: 168072
Add JSON Extractor as a child of the request which produces the above JSON response and configure it as follows:
This will produce the following JMeter Variables (you can validate them using Debug Sampler):
week_1=["Week","Event Count"]
week_2=["3\/13\/17","1"]
week_3=["3\/20\/17","1"]
week_4=["3\/27\/17","1"]
week_5=["4\/3\/17","1"]
week_6=["4\/10\/17","1"]
week_7=["4\/17\/17","1"]
week_matchNr=7
You are particularly interested in the latter one
Add Response Assertion as a child of the same request and configure it as follows:
week_matchNr
Equals
7
This way your sampler will pass if number of matches will be equal to 7 and otherwise it will fail. See How to Use JMeter Assertions in Three Easy Steps article to learn more about using assertions in JMeter tests.
Upvotes: 8