How To Set JMeter Vars From Within WebDriver Sampler?
// I had previously used a CSS/JQuery extractor to get a URL from a page and add it to JMeter vars - accessing it here var pageURL = '${valueFromJmeterVars}'; // navigate to that
Solution 1:
You can access JMeter API classes from within the WebDriver Sampler, it's implemented as JSR 223 standard for instance you can refer JMeter Variables (aka vars
as follows)
In the WebDriver Sampler:
var ctx = org.apache.jmeter.threads.JMeterContextService.getContext()
var vars = ctx.getVariables();
vars.put('foo','bar')
Now you have ${foo}
variable with the value of bar
See The WebDriver Sampler: Your Top 10 Questions Answered guide for more WDS sampler tips and tricks.
Solution 2:
It won't work because 'vars' in not defined in WebDriver Sampler as in for instance BeanShell Sampler.
Solution 3:
There isn't a clean way to do this, but it is possible. You can set the response headers in your WebDriver sampler:
WDS.sampleResult.setResponseHeaders(reserveASpotButton.isEnabled())
Then you can use a regular expression extractor to pull the data from the response headers.
Post a Comment for "How To Set JMeter Vars From Within WebDriver Sampler?"