In case you prefer to use JEXL, I've just discovered that the JEXL function does have access to some variables. This was added in 2.3 (RC3) but not documented ;-)
The variables are: ctx - JMeter context vars - JMeter variables threadName sampler - current Sampler (if any) sampleResult - current SampleResult (if any) The "vars" variable should be all you need. The methods you need are: vars.get(String varname) and vars.put(String varname, String value) [Same as for BeanShell] On 09/11/2007, sebb <[EMAIL PROTECTED]> wrote: > There are a few scripts that come with JMeter - the .bshrc files. > > Also there have been a few discussion about using BeanShell on this list. > > > On 09/11/2007, driesie <[EMAIL PROTECTED]> wrote: > > > > Thanks. > > I suspected Beanshell may be the best bet. > > I've put off trying that out because I'm not a Java programmer, but I should > > be able to figure out simple constructs. > > > > > > > > sebb-2 wrote: > > > > > > On 08/11/2007, driesie <[EMAIL PROTECTED]> wrote: > > >> > > >> Thanks for the quick reply again. > > >> > > >> It's a bit odd. > > >> I think what was confusing is that I didn't have a sampler as part of the > > >> foreach loop, I just want to build up a string during this loop and then > > >> use > > >> it in a sampler afterwards. > > > > > > Pre-Processors apply to samplers, so they won't run without a sampler. > > > > > >> After playing around with it for a more, I realised that when I put a > > >> "Test > > >> Action" sampler (0 Pause) in the scenario, then it does work ... kind of. > > >> So I have > > >> - sampler > > >> - xpath extractor - reference: TRANSACTIONIDS > > >> - Foreach controller - input: TRANSACTIONIDS, output: RETURNID > > >> - User Parameters: TRANSACTIONID_XML = > > >> ${TRANSACTIONID_XML}<int>${RETURNID}</int> > > >> - Test Action (0 Pause) > > >> - sampler: in here I use ${TRANSACTIONID_XML} > > >> > > >> And this will print something along the lines of: > > >> <int>${RETURNID}</int><int>-2</int><int>-18</int><int>-13</int> > > >> > > >> Which is correct, except the timing, i.e. it always updates the variable > > >> before the foreach loop returns (RETURNID), no matter where I place the > > >> User > > >> Parameters. So the above output is also missing the last element in the > > >> collection. > > >> I hope this kind of makes sense. > > >> > > >> It's workable as I can use a javascript function to tidy it up, but it > > >> seems > > >> a bit hacky. > > > > > > Might be better to dispense with the ForEach Controller and use > > > BeanShell (Pre-Processor or Function) to generate the string directly. > > > I don't think one can use JavaScript or Jexl functions - because > > > these cannot access variables with dynamic names - whereas in > > > BeanShell one can use vars.get(varName) > > > > > > If you know how in advance how many matches there will be then of > > > course you can just concatenate the variables. > > > > > > Or if you know that there will be (say) 3, 5 or 6 matches, you could > > > use the If or Switch Controller in conjunction with the appropriate > > > fixed list of variables. > > > > > >> Dries. > > >> > > >> > > >> sebb-2 wrote: > > >> > > > >> > On 08/11/2007, driesie <[EMAIL PROTECTED]> wrote: > > >> >> > > >> >> Thanks. I didn't realise it would be processed just once, that's very > > >> >> useful > > >> >> to know. > > >> >> > > >> >> I tried to change it, however, I don't think it's a solution for my > > >> >> problem. > > >> >> > > >> >> I now have > > >> >> - sampler > > >> >> - xpath extractor - reference: TRANSACTIONIDS > > >> >> - Foreach controller - input: TRANSACTIONIDS, output: RETURNID > > >> >> - User Parameters: TRANSACTIONID_XML = > > >> >> ${TRANSACTIONID_XML}<int>${RETURNID}</int> > > >> > > > >> > That's recursive... > > >> > > > >> >> - sampler: in here I use ${TRANSACTIONID_XML} > > >> > > > >> > Try using RETURNID only and see if that varies. > > >> > > > >> > If not, check that UP "Update once per iteration" is not checked. > > >> > > > >> >> ${TRANSACTIONID_XML} outputs > > >> "${TRANSACTIONID_XML}<int>${RETURNID}</int>" > > >> >> > > >> >> So it seems that the variable doesn't get updated in each iteration of > > >> >> the > > >> >> foreach loop as I was hoping. > > >> >> The extractor definitly returns a set as I do have values for > > >> >> ${TRANSACTIONIDS} and ${TRANSACTIONIDS_matchNr} > > >> >> > > >> >> > > >> >> Dries. > > >> >> > > >> >> > > >> >> sebb-2 wrote: > > >> >> > > > >> >> > On 08/11/2007, driesie <[EMAIL PROTECTED]> wrote: > > >> >> >> > > >> >> >> Hi, > > >> >> >> > > >> >> >> I'm new to JMeter, and I have been struggling with something for > > >> the > > >> >> last > > >> >> >> day or so. > > >> >> >> I am writing a test plan that envolves requesting various web > > >> services > > >> >> >> (Webservice SOAP request). > > >> >> >> I have everything working where I can "predict" the Soap message to > > >> >> post, > > >> >> >> but now I am working on a next test for which the message will be > > >> >> >> constructed depending on the response of a previous request. > > >> >> >> So what I did is the following: > > >> >> >> > > >> >> >> - Created the first Webservice sampled > > >> >> >> - Use a XPath Extractor post processor, using "TRANSACTIONIDS" as > > >> >> >> Reference > > >> >> >> name. The xPath query returns a collection > > >> >> >> - Foreach Controller with input variable prefix "TRANSACTIONIDS", > > >> >> output > > >> >> >> name "RETURNID" > > >> >> >> - User Defined Variables config element with the following: > > >> >> >> XML -> ${XML}<id>${RETURNID}</id> > > >> >> > > > >> >> > The UDV is a configuration element, and is processed once. > > >> >> > > > >> >> > Try the User Parameters Pre-Processor instead for values that > > >> change. > > >> >> > [You only need one "User" column] > > >> >> > > > >> >> >> - Then I use the XML variable in the soap message for a second > > >> >> sampler. > > >> >> >> > > >> >> >> This doesn't work however. I am pretty sure everything works up to > > >> the > > >> >> >> foreach controller as I can print ${TRANSACTIONIDS} and > > >> >> >> ${TRANSACTIONIDS_matchNr} fine, so I know it is returning elements. > > >> >> Also, > > >> >> >> if > > >> >> >> I print ${RETURNID} it returns the last element in the collection. > > >> >> >> So the problem is that the bit where I try to combine all elements > > >> >> into a > > >> >> >> new variable isn't working. In fact, it looks like whatever > > >> variable > > >> >> >> defined > > >> >> >> in that user defined variables config element isn't working. > > >> >> >> > > >> >> >> What am I doing wrong, and would there be a better way of > > >> >> concatinating > > >> >> >> those elements into an XML string that I can use in the SOAP > > >> message? > > >> >> >> > > >> >> >> Thanks, > > >> >> >> > > >> >> >> Dries. > > >> >> >> > > >> >> >> -- > > >> >> >> View this message in context: > > >> >> >> > > >> >> > > >> http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13643994 > > >> >> >> Sent from the JMeter - User mailing list archive at Nabble.com. > > >> >> >> > > >> >> >> > > >> >> >> > > >> --------------------------------------------------------------------- > > >> >> >> To unsubscribe, e-mail: [EMAIL PROTECTED] > > >> >> >> For additional commands, e-mail: > > >> [EMAIL PROTECTED] > > >> >> >> > > >> >> >> > > >> >> > > > >> >> > > > >> --------------------------------------------------------------------- > > >> >> > To unsubscribe, e-mail: [EMAIL PROTECTED] > > >> >> > For additional commands, e-mail: [EMAIL PROTECTED] > > >> >> > > > >> >> > > > >> >> > > > >> >> > > >> >> -- > > >> >> View this message in context: > > >> >> > > >> http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13650339 > > >> >> Sent from the JMeter - User mailing list archive at Nabble.com. > > >> >> > > >> >> > > >> >> --------------------------------------------------------------------- > > >> >> To unsubscribe, e-mail: [EMAIL PROTECTED] > > >> >> For additional commands, e-mail: [EMAIL PROTECTED] > > >> >> > > >> >> > > >> > > > >> > --------------------------------------------------------------------- > > >> > To unsubscribe, e-mail: [EMAIL PROTECTED] > > >> > For additional commands, e-mail: [EMAIL PROTECTED] > > >> > > > >> > > > >> > > > >> > > >> -- > > >> View this message in context: > > >> http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13651096 > > >> Sent from the JMeter - User mailing list archive at Nabble.com. > > >> > > >> > > >> --------------------------------------------------------------------- > > >> To unsubscribe, e-mail: [EMAIL PROTECTED] > > >> For additional commands, e-mail: [EMAIL PROTECTED] > > >> > > >> > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > -- > > View this message in context: > > http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13664890 > > Sent from the JMeter - User mailing list archive at Nabble.com. > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]