tags:

views:

29

answers:

2

I have a page that uses JQuery. This page also has hidden fields whose value is populated dynamically by JQuery (upon dropdown selection).

Now I have an javascript/jquery expression similar to this $('*[name=staffid]').val() - this expression provides me the selected value. I would like to store this value in a variable within JMeter so that I can pass it to subsequent calls or during submit.

How do I evaluate/execute this expression within JMeter so that I can pass these values to subsequent request(s) or store it in a variable for further use.

A: 

You can try the javascript function, ${__javaScript()}

http://jakarta.apache.org/jmeter/usermanual/functions.html#__javaScript

or a beanshell processor, which can execute javascript

http://jakarta.apache.org/jmeter/usermanual/component_reference.html#BeanShell_PreProcessor

BlackGaff
I tried this but JMeter complains that $ reference to jquery is not recognizable jmeter.extractor.BSFPostProcessor: Problem in BSF script org.apache.bsf.BSFException: JavaScript Error: Internal Error: org.mozilla.javascript.EcmaError: ReferenceError: "$" is not defined
Bala
Yes, the JavaScript won't work because JMeter is just running a JavaScript expression without any context of the actual page. That's just how JMeter works: like almost every load testing tool it doesn't really process the page, set up the DOM, evaluate JavaScript, etc.
Patrick Lightbody
A: 

You won't be able to evaluate jQuery expressions against pages using JMeter. I wish it were that easy, but that jQuery needs a fully running DOM + JavaScript engine and that's just not provided by JMeter.

Shameless plug: the company I started, BrowserMob, does load testing by running actual browsers driven by Selenium. When using a real browser, you don't have to do this kind of stuff. Check it out at http://browsermob.com.

Patrick Lightbody