Iam using the ruby-jmeter gem to write DSL scripts for doing performance tests automation..
I find this pretty useful to navigate to my API URLs, post data, assert for expected result and generate performance trends reports..
Iam getting stuck while using the extract regex: '', name: '' syntax in ruby-jmeter.
I want something like: I Visit http :// domain/api/user?q=create,
I post a raw JSON data as input and I get required JSON response. I want to extract a pattern from this response and use this value dynamically so that I can provide it as input to my raw JSON input to Visit http: //domain/api/user?q=read
Basically i was trying:
visit name: 'CreateUser', url: "<url link>",<br>
method: "post",<br>
domain: "<domain>",<br>
path: 'api/user?q=create', <br>
raw_body: <input json> do<br>
#extract a pattern from response<br>
extract regex: '"Username":"(.+?)"', name: 'userName'<br>
puts '${userName}'<br>
# rest of code here.. <br>
# I want to use ${username} as input to my next Visit call<br>
end
Can somebody who have looked into ruby-jmeter help me here plssss?
thanks, Vishi.
Ruby-JMeter is a DSL, it only evaluates ruby code when it generates a test plan (.jmx), it doesn't run the test plan and evaluate ruby code at the same time.
In your example this will generate a regular expression extractor in JMeter:
The following ruby code won't know anything about ${} style JMeter variables:
If the regular expression matches, then the relevant
${userName}
JMeter variable will be set and you should be able to use it in subsequent requests:For more detailed examples testing APIs with Ruby please see this blog post