Discussion:
Variables in ForEach Controller
driesie
2007-11-08 09:41:43 UTC
Permalink
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>
- 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.
sebb
2007-11-08 14:24:39 UTC
Permalink
Post by driesie
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.
- 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"
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]
Post by driesie
- 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.
---------------------------------------------------------------------
driesie
2007-11-08 16:24:17 UTC
Permalink
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>
- sampler: in here I use ${TRANSACTIONID_XML}

${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.
Post by sebb
Post by driesie
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.
- 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"
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]
Post by driesie
- 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.
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13643994
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
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.
sebb
2007-11-08 16:29:23 UTC
Permalink
Post by driesie
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...
Post by driesie
- 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.
Post by driesie
${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.
Post by sebb
Post by driesie
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.
- 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"
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]
Post by driesie
- 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.
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13643994
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
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.
---------------------------------------------------------------------
driesie
2007-11-08 16:57:49 UTC
Permalink
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.
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.

Dries.
Post by sebb
Post by driesie
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...
Post by driesie
- 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.
Post by driesie
${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.
Post by sebb
Post by driesie
Hi,
I'm new to JMeter, and I have been struggling with something for the
last
Post by sebb
Post by driesie
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,
Post by sebb
Post by driesie
but now I am working on a next test for which the message will be
constructed depending on the response of a previous request.
- 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
Post by sebb
Post by driesie
name "RETURNID"
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]
Post by driesie
- Then I use the XML variable in the soap message for a second
sampler.
Post by sebb
Post by driesie
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,
Post by sebb
Post by driesie
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
Post by sebb
Post by driesie
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
Post by sebb
Post by driesie
those elements into an XML string that I can use in the SOAP message?
Thanks,
Dries.
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13643994
Post by sebb
Post by driesie
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13650339
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
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.
sebb
2007-11-08 17:51:56 UTC
Permalink
Post by driesie
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.
Post by driesie
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}
<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.
Post by driesie
Dries.
Post by sebb
Post by driesie
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...
Post by driesie
- 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.
Post by driesie
${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.
Post by sebb
Post by driesie
Hi,
I'm new to JMeter, and I have been struggling with something for the
last
Post by sebb
Post by driesie
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,
Post by sebb
Post by driesie
but now I am working on a next test for which the message will be
constructed depending on the response of a previous request.
- 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
Post by sebb
Post by driesie
name "RETURNID"
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]
Post by driesie
- Then I use the XML variable in the soap message for a second
sampler.
Post by sebb
Post by driesie
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,
Post by sebb
Post by driesie
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
Post by sebb
Post by driesie
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
Post by sebb
Post by driesie
those elements into an XML string that I can use in the SOAP message?
Thanks,
Dries.
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13643994
Post by sebb
Post by driesie
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13650339
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
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.
---------------------------------------------------------------------
driesie
2007-11-09 10:58:35 UTC
Permalink
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.
Post by sebb
Post by driesie
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.
Post by driesie
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}
<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.
Post by driesie
Dries.
Post by sebb
Post by driesie
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...
Post by driesie
- 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.
Post by driesie
${TRANSACTIONID_XML} outputs
"${TRANSACTIONID_XML}<int>${RETURNID}</int>"
Post by sebb
Post by driesie
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.
Post by sebb
Post by driesie
Hi,
I'm new to JMeter, and I have been struggling with something for
the
Post by sebb
Post by driesie
last
Post by sebb
Post by driesie
day or so.
I am writing a test plan that envolves requesting various web
services
Post by sebb
Post by driesie
Post by sebb
Post by driesie
(Webservice SOAP request).
I have everything working where I can "predict" the Soap message to
post,
Post by sebb
Post by driesie
but now I am working on a next test for which the message will be
constructed depending on the response of a previous request.
- 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
Post by sebb
Post by driesie
name "RETURNID"
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.
Post by sebb
Post by driesie
Post by sebb
[You only need one "User" column]
Post by driesie
- Then I use the XML variable in the soap message for a second
sampler.
Post by sebb
Post by driesie
This doesn't work however. I am pretty sure everything works up to
the
Post by sebb
Post by driesie
Post by sebb
Post by driesie
foreach controller as I can print ${TRANSACTIONIDS} and
${TRANSACTIONIDS_matchNr} fine, so I know it is returning elements.
Also,
Post by sebb
Post by driesie
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
Post by sebb
Post by driesie
new variable isn't working. In fact, it looks like whatever
variable
Post by sebb
Post by driesie
Post by sebb
Post by driesie
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
Post by sebb
Post by driesie
those elements into an XML string that I can use in the SOAP
message?
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Thanks,
Dries.
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13643994
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
Post by sebb
Post by driesie
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13650339
Post by sebb
Post by driesie
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13651096
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
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.
sebb
2007-11-09 12:27:13 UTC
Permalink
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.
Post by driesie
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.
Post by sebb
Post by driesie
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.
Post by driesie
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}
<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.
Post by driesie
Dries.
Post by sebb
Post by driesie
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...
Post by driesie
- 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.
Post by driesie
${TRANSACTIONID_XML} outputs
"${TRANSACTIONID_XML}<int>${RETURNID}</int>"
Post by sebb
Post by driesie
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.
Post by sebb
Post by driesie
Hi,
I'm new to JMeter, and I have been struggling with something for
the
Post by sebb
Post by driesie
last
Post by sebb
Post by driesie
day or so.
I am writing a test plan that envolves requesting various web
services
Post by sebb
Post by driesie
Post by sebb
Post by driesie
(Webservice SOAP request).
I have everything working where I can "predict" the Soap message to
post,
Post by sebb
Post by driesie
but now I am working on a next test for which the message will be
constructed depending on the response of a previous request.
- 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
Post by sebb
Post by driesie
name "RETURNID"
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.
Post by sebb
Post by driesie
Post by sebb
[You only need one "User" column]
Post by driesie
- Then I use the XML variable in the soap message for a second
sampler.
Post by sebb
Post by driesie
This doesn't work however. I am pretty sure everything works up to
the
Post by sebb
Post by driesie
Post by sebb
Post by driesie
foreach controller as I can print ${TRANSACTIONIDS} and
${TRANSACTIONIDS_matchNr} fine, so I know it is returning elements.
Also,
Post by sebb
Post by driesie
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
Post by sebb
Post by driesie
new variable isn't working. In fact, it looks like whatever
variable
Post by sebb
Post by driesie
Post by sebb
Post by driesie
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
Post by sebb
Post by driesie
those elements into an XML string that I can use in the SOAP
message?
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Thanks,
Dries.
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13643994
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
Post by sebb
Post by driesie
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13650339
Post by sebb
Post by driesie
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13651096
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
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.
---------------------------------------------------------------------
sebb
2007-11-09 14:16:52 UTC
Permalink
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]
Post by sebb
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.
Post by driesie
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.
Post by sebb
Post by driesie
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.
Post by driesie
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}
<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.
Post by driesie
Dries.
Post by sebb
Post by driesie
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...
Post by driesie
- 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.
Post by driesie
${TRANSACTIONID_XML} outputs
"${TRANSACTIONID_XML}<int>${RETURNID}</int>"
Post by sebb
Post by driesie
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.
Post by sebb
Post by driesie
Hi,
I'm new to JMeter, and I have been struggling with something for
the
Post by sebb
Post by driesie
last
Post by sebb
Post by driesie
day or so.
I am writing a test plan that envolves requesting various web
services
Post by sebb
Post by driesie
Post by sebb
Post by driesie
(Webservice SOAP request).
I have everything working where I can "predict" the Soap message to
post,
Post by sebb
Post by driesie
but now I am working on a next test for which the message will be
constructed depending on the response of a previous request.
- 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
Post by sebb
Post by driesie
name "RETURNID"
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.
Post by sebb
Post by driesie
Post by sebb
[You only need one "User" column]
Post by driesie
- Then I use the XML variable in the soap message for a second
sampler.
Post by sebb
Post by driesie
This doesn't work however. I am pretty sure everything works up to
the
Post by sebb
Post by driesie
Post by sebb
Post by driesie
foreach controller as I can print ${TRANSACTIONIDS} and
${TRANSACTIONIDS_matchNr} fine, so I know it is returning elements.
Also,
Post by sebb
Post by driesie
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
Post by sebb
Post by driesie
new variable isn't working. In fact, it looks like whatever
variable
Post by sebb
Post by driesie
Post by sebb
Post by driesie
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
Post by sebb
Post by driesie
those elements into an XML string that I can use in the SOAP
message?
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Thanks,
Dries.
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13643994
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
Post by sebb
Post by driesie
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13650339
Post by sebb
Post by driesie
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13651096
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
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.
---------------------------------------------------------------------
driesie
2007-11-10 21:16:09 UTC
Permalink
Thanks.

I got it to work using Beanshell quite easily actually. So wasn't so hard as
I was fearing it would be.

Thanks for all your help!
Post by sebb
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.
Post by driesie
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.
Post by sebb
Post by driesie
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
Post by sebb
Post by driesie
foreach loop, I just want to build up a string during this loop and
then
Post by sebb
Post by driesie
use
it in a sampler afterwards.
Pre-Processors apply to samplers, so they won't run without a sampler.
Post by driesie
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.
Post by sebb
Post by driesie
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}
<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
Post by sebb
Post by driesie
before the foreach loop returns (RETURNID), no matter where I place
the
Post by sebb
Post by driesie
User
Parameters. So the above output is also missing the last element in
the
Post by sebb
Post by driesie
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.
Post by driesie
Dries.
Post by sebb
Post by driesie
Thanks. I didn't realise it would be processed just once, that's
very
Post by sebb
Post by driesie
Post by sebb
Post by driesie
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...
Post by driesie
- 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.
Post by driesie
${TRANSACTIONID_XML} outputs
"${TRANSACTIONID_XML}<int>${RETURNID}</int>"
Post by sebb
Post by driesie
So it seems that the variable doesn't get updated in each iteration
of
Post by sebb
Post by driesie
Post by sebb
Post by driesie
the
foreach loop as I was hoping.
The extractor definitly returns a set as I do have values for
${TRANSACTIONIDS} and ${TRANSACTIONIDS_matchNr}
Dries.
Post by sebb
Post by driesie
Hi,
I'm new to JMeter, and I have been struggling with something for
the
Post by sebb
Post by driesie
last
Post by sebb
Post by driesie
day or so.
I am writing a test plan that envolves requesting various web
services
Post by sebb
Post by driesie
Post by sebb
Post by driesie
(Webservice SOAP request).
I have everything working where I can "predict" the Soap message
to
Post by sebb
Post by driesie
Post by sebb
Post by driesie
post,
Post by sebb
Post by driesie
but now I am working on a next test for which the message will
be
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Post by sebb
Post by driesie
constructed depending on the response of a previous request.
- Created the first Webservice sampled
- Use a XPath Extractor post processor, using "TRANSACTIONIDS"
as
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Reference
name. The xPath query returns a collection
- Foreach Controller with input variable prefix
"TRANSACTIONIDS",
Post by sebb
Post by driesie
Post by sebb
Post by driesie
output
Post by sebb
Post by driesie
name "RETURNID"
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.
Post by sebb
Post by driesie
Post by sebb
[You only need one "User" column]
Post by driesie
- Then I use the XML variable in the soap message for a second
sampler.
Post by sebb
Post by driesie
This doesn't work however. I am pretty sure everything works up
to
Post by sebb
Post by driesie
the
Post by sebb
Post by driesie
Post by sebb
Post by driesie
foreach controller as I can print ${TRANSACTIONIDS} and
${TRANSACTIONIDS_matchNr} fine, so I know it is returning
elements.
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Also,
Post by sebb
Post by driesie
if
I print ${RETURNID} it returns the last element in the
collection.
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Post by sebb
Post by driesie
So the problem is that the bit where I try to combine all
elements
Post by sebb
Post by driesie
Post by sebb
Post by driesie
into a
Post by sebb
Post by driesie
new variable isn't working. In fact, it looks like whatever
variable
Post by sebb
Post by driesie
Post by sebb
Post by driesie
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
Post by sebb
Post by driesie
those elements into an XML string that I can use in the SOAP
message?
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Thanks,
Dries.
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13643994
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
Post by sebb
Post by driesie
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13650339
Post by sebb
Post by driesie
Post by sebb
Post by driesie
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
Post by sebb
Post by driesie
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13651096
Post by sebb
Post by driesie
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13664890
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
View this message in context: http://www.nabble.com/Variables-in-ForEach-Controller-tf4769958.html#a13685942
Sent from the JMeter - User mailing list archive at Nabble.com.
Loading...