However using normal JMeter functions we can easily implement this functionality.
Assume that you have an XPath post processor that is attached to a HTTP Sampler and is returning n values into a variable called testXPATH. if we now want to select a value at random what we need to use is
${__V(testXPATH_${__Random(1,${testXPATH_matchNr})})}
But thats a mouthfull and needs an explanation
${testXPATH_matchNr}
returns the count of how many elements matched. We are assuming that some values are going to be selected, otherwise you need an IF controller to check the condition.
${__Random(1,${testXPATH_matchNr})}
Will then select an integer between 1 and the count of the values (TODO check if we need to add 1)
${__V(testXPATH_${__Random(1,${testXPATH_matchNr})})}}
Finally we form a string of the form testXPATH_n e.g. testXPATH_3 which is then passed to the __V function which will get us the value for the variable
http://jakarta.apache.org/jmeter/usermanual/functions.html
Note that running TIDY on HTML , followed by parsing it to create a DOM structure and finally running an XPATH query against it is signifcantly slower than just running a Regex against a String. If you need to generate a large load and you have limited resources available to you, then the XPATH extractor is probably not the best alternative.
0 comments:
Post a Comment