SetUp part of my Jmeter script contains steps to bypass login page of my Web Application before generating real load. As a result of these steps, server sets specific cookie that proves successful loginization.
To do that, my script should execute Javascript function injected in response by server. Since it's a one-time procedure, I do it using WebDriver and execute Javascript within browser instance.
But I definitely can't do the same as a part of load thread as WebDriver is not a good idea (at all) for performance testing.
However, I'm still wondering is it a way to calculate JS without creating a browser instance, because my JS script is nothing but arithmetic calculations (complex though). So,
Thanks for any ideas in advance.
You can use JSR223 Sampler, choose javascript
from "Language" dropdown and place your code in "Script" area
You can use single browser instance using WebDriver Sampler for all threads in a loop, something like:
var ctx = org.apache.jmeter.threads.JMeterContextService.getContext()
var vars = ctx.getVariables();
for (var i=0; i< THREADS_NUMBER; i++) {
WDS.browser.manage().deleteAllCookies()
WDS.browser.get('LOGIN_PAGE_URL')
var cookie = WDS.browser.manage().getCookieNamed("COOKIE_NAME").getValue();
vars.put("cookie" + i, cookie);
}
it will generate JMeter Variables like:
cookie1=foo
cookie2=bar
etc.
So you will be able to refer variable values using __threadNum() function where required like:
${__evalVar(cookie${__threadNum})}
See The WebDriver Sampler: Your Top 10 Questions Answered guide for more information on using the WebDriver Sampler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With