You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Mark24 <mh...@infomedia.com.au> on 2008/10/01 04:43:43 UTC

Re: how do I pass a value obtained in "Thread Group 1" (with "XPath Extractor" from a "WebService(SOAP) Request") to "Thread Group 2" for use as input to "WebService(SOAP) Request"


>From my observations it looks like if a parameter is set to a variable in
BeanShell PostProcessor i.e. ${__setProperty(parameterName,variableName)},
printing the parameterName value to console i.e.
print(${__P(parameterName)}) works as expected (if variableName was declared
in BeanShell as: String variableName = “mary had a little lamb”, it would
print “mary had a little lamb”).

However, in BeanShell PostProcessor in a separate ThreadGroup
print(${__P(parameterName)}) causes an error because variableName doesn’t
exist (not in scope I guess).

Setting parameterName to a literal eg. “quick brown fox” prints as expected
in both ThreadGroups.

I’ve come to the conclusion that ${__P(parameterName)} evaluates to the
variable variableName (parameterName is a pointer to the variable perhaps?)
and works in the initial ThreadGroup as variableName is within scope
containing value “mary had a little lamb” but doesn’t work in the second
ThreadGroup as variableName is out now out of scope.


In a nutshell this is what I think is happening ("a <- b" means a request
value from b):


Initial ThreadGroup:
${__P(parameterName)}  <- variableName <-  “mary had a little lamb”

Second ThreadGroup:
${__P(parameterName)}  <- variableName <-  !!Error, variableName doesn’t
exist here!!


This has really got me snookered passing values between ThreadGroups; I
don’t have an initialisation file so it must be my code which is incorrect:

ThreadGroup1’s
${__setProperty(securityid,bsh.args[0],true)};

Or 

ThreadGroup2’s
${__P(securityid)};


Thanks guys,
Mark




sebb-2-2 wrote:
> 
> On 29/09/2008, Mark24 <mh...@infomedia.com.au> wrote:
>>
>>  Thanks Sebb. I've tried your suggestions but had hit another snag:
>>
>>  I call Jmeter at the command window by "Jmeter -Jsecurityid=123" to
>> create a
>>  parameter securityid with default value "123".
>>
>>
>>  + Test Plan
>>  ++ Thread Group1
>>  +++ WebService(SOAP) Request1
>>  ++++ XPath Extractor
>>  ++++ BeanShell PostProcessor1
>>
>>  ++ Thread Group2
>>  +++ WebService(SOAP) Request2
>>  ++++ BeanShell PostProcessor2
>>
>>
>>  In Thread Group1, XPath Extractor I set:
>>  - Reference Name = theSID
>>  - Xpath query = //sid
>>  - Default Value = "nomatchfound"
>>
>>  In Thread Group1, BeanShell PostProcessor1 I set:
>>  - Reset Interpreter = False
>>  - Parameters = ${theSID}
>>  - Script = ${__setProperty(securityid,bsh.args[0],true)};
>>  print(${__P(securityid)});
>>
>>
>>  In Thread Group2, BeanShell PostProcessor2 I set:
>>  - Reset Interpreter = False
>>  - Parameters =
>>  - Script = print(${__P(securityid)});
>>
>>
>>  I run this Test Plan, it extracts //sid (say, "123456", sets securityid
>> to
>>  "123456" and prints to console "123456" in BeanShell PostProcessor1, but
>> in
>>  Thread Group2's BeanShell PostProcessor2 it doesn't print to console but
>>  instead logs an error in jmeter.log mentioning "Error invoking bsh
>> method:
>>  eval Sourced file: inline evaluation of: ''print(bsh.args[0]);''"
>>
>>
>>  I expect print(${__P(securityid)}); in BeanShell PostProcessor2 to print
>>  "123456" but is looks like it is evaluating bsh.args[0] and because it
>>  doesn't exist here it errors out.
>>
>>  What am i doing wrong?
> 
> Neither JMeter nor BeanShell will add ''print(bsh.args[0]);'' to the
> script by themselves, so there must be an error in your BeanShell
> script - or perhaps initialisation file.
> 
>>
>>
>>
>>
>>  sebb-2-2 wrote:
>>  >
>>  > On 26/09/2008, Mark24 <mh...@infomedia.com.au> wrote:
>>  >>
>>  >>  Thanks for your reply sebb, you are very informative (i've been
>> reading
>>  >> your
>>  >>  answer to questions quite often over the last 3 days ive been using
>>  >> JMeter).
>>  >>
>>  >>  My grand plan is to regression test my company's MS web services by
>>  >> loging
>>  >>  in once to get the security id, then spawn multiple virtual users to
>>  >> work
>>  >>  together to call the other WS methods using a collection of inputs
>> from
>>  >> a
>>  >>  database. certain values from the responses are planned to be
>> inserted
>>  >> into
>>  >>  a database to later run some sql to compare these values against a
>> test
>>  >>  baseline database.
>>  >>
>>  >>  I was using one thread group which was spawning a single user to to
>> get
>>  >> the
>>  >>  security id, then the second thread group would spawn n virtual
>> users.
>>  >>
>>  >
>>  > OK, it was not clear that you wanted to use a single id in multiple
>>  > threads.
>>  >
>>  > In which case, use two thread groups, and set them to run one after
>>  > another.
>>  >
>>  > Extract the id you want to use, and save it as a JMeter Property using
>>  > the function:
>>  >
>>  >
>> http://jakarta.apache.org/jmeter/usermanual/functions.html#__setProperty
>>  >
>>  > You can then use the __P() function to retrieve the value in the
>>  > second thread group.
>>  >
>>  > Or if you already have a lot of samplers using a variable, just add a
>>  > user parameters pre-processor to the first one and copy the property
>>  > to the variable there.
>>  >
>>  >>  I'm possibly approaching the solution to my problem incorrectly so
>>  >> please
>>  >>  comment or point me to some reading material. My Jmeter textbook has
>>  >> been
>>  >>  order on Amazon but until then, the jmeter docs and forums like this
>> are
>>  >> my
>>  >>  friends.
>>  >
>>  > There's also quite a lot of information on the Wiki.
>>  >
>>  >>  Thanks again Sebb,
>>  >>
>>  >>  Mark
>>  >>
>>  >>
>>  >>  sebb-2-2 wrote:
>>  >>  >
>>  >>  > On 26/09/2008, Mark24 <mh...@infomedia.com.au> wrote:
>>  >>  >>
>>  >>  >>  In Jmeter 2.3.2, how do I pass a value obtained in "Thread Group
>> 1"
>>  >>  >> (with
>>  >>  >>  "XPath Extractor" from a "WebService(SOAP) Request") to "Thread
>>  >> Group 2"
>>  >>  >> for
>>  >>  >>  use as input to "WebService(SOAP) Request"
>>  >>  >>
>>  >>  >>  Graphically:
>>  >>  >>
>>  >>  >>  "Thread Group 1"
>>  >>  >>    "WebService(SOAP) Request"  //login() WS method which returns
>> a
>>  >>  >> security
>>  >>  >>  ID
>>  >>  >>    "XPath Extractor"  //extract security ID to security_ID
>> variable
>>  >>  >>  "Thread Group 2"
>>  >>  >>    "WebService(SOAP) Request"  //use ${security_ID} as a
>> parameter to
>>  >>  >> this
>>  >>  >>  Search() WS method
>>  >>  >>
>>  >>  >>
>>  >>  >>  Variable security_ID declared in "Thread Group 1"'s "XPath
>>  >> Extractor"
>>  >>  >> seems
>>  >>  >>  to be very narrowly scoped as "${security_ID}" is literally used
>> as
>>  >>  >> input to
>>  >>  >>  "Thread Group 2"'s "WebService(SOAP) Request" instead of the
>> value
>>  >> of
>>  >>  >>  ${security_ID}.
>>  >>  >>
>>  >>  >>  I've tried declaring the security_ID variable in "Test Plan to
>> use"
>>  >> but
>>  >>  >> this
>>  >>  >>  doesn't work (${security_ID} resolves to the value i set during
>>  >>  >> declaration
>>  >>  >>  instead of the extracted value).
>>  >>  >
>>  >>  > Why not use the same Thread Group for the two SOAP requests?
>>  >>  >
>>  >>  > e.g.
>>  >>  >
>>  >>  > Thread Group
>>  >>  > + SOAP
>>  >>  > + + XPath
>>  >>  > + SOAP using variable
>>  >>  >
>>  >>  > If you want to run multiple requests with the same variable, just
>> add
>>  >>  > them at the end, or enclose in a loop:
>>  >>  >
>>  >>  > Thread Group
>>  >>  > + SOAP
>>  >>  > + + XPath
>>  >>  > + Loop
>>  >>  > + + SOAP using variable
>>  >>  >
>>  >>  >>  Thanks for any help,
>>  >>  >>  Mark
>>  >>  >>
>>  >>  >>
>>  >>  >>  --
>>  >>  >>  View this message in context:
>>  >>  >>
>>  >>
>> http://www.nabble.com/how-do-I-pass-a-value-obtained-in-%22Thread-Group-1%22-%28with-%22XPath-Extractor%22-from-a-%22WebService%28SOAP%29-Request%22%29-to-%22Thread-Group-2%22-for-use-as-input-to-%22WebService%28SOAP%29-Request%22-tp19683794p19683794.html
>>  >>  >>  Sent from the JMeter - User mailing list archive at Nabble.com.
>>  >>  >>
>>  >>  >>
>>  >>  >>
>>  >> ---------------------------------------------------------------------
>>  >>  >>  To unsubscribe, e-mail:
>> jmeter-user-unsubscribe@jakarta.apache.org
>>  >>  >>  For additional commands, e-mail:
>> jmeter-user-help@jakarta.apache.org
>>  >>  >>
>>  >>  >>
>>  >>  >
>>  >>  >
>> ---------------------------------------------------------------------
>>  >>  > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>  >>  > For additional commands, e-mail:
>> jmeter-user-help@jakarta.apache.org
>>  >>  >
>>  >>  >
>>  >>  >
>>  >>
>>  >>
>>  >> --
>>  >>  View this message in context:
>>  >>
>> http://www.nabble.com/how-do-I-pass-a-value-obtained-in-%22Thread-Group-1%22-%28with-%22XPath-Extractor%22-from-a-%22WebService%28SOAP%29-Request%22%29-to-%22Thread-Group-2%22-for-use-as-input-to-%22WebService%28SOAP%29-Request%22-tp19683794p19686226.html
>>  >>
>>  >> Sent from the JMeter - User mailing list archive at Nabble.com.
>>  >>
>>  >>
>>  >> 
>> ---------------------------------------------------------------------
>>  >>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>  >>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>  >>
>>  >>
>>  >
>>  > ---------------------------------------------------------------------
>>  > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>  > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>  >
>>  >
>>  >
>>
>>  --
>>
>> View this message in context:
>> http://www.nabble.com/how-do-I-pass-a-value-obtained-in-%22Thread-Group-1%22-%28with-%22XPath-Extractor%22-from-a-%22WebService%28SOAP%29-Request%22%29-to-%22Thread-Group-2%22-for-use-as-input-to-%22WebService%28SOAP%29-Request%22-tp19683794p19718151.html
>>
>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>
>>
>>  ---------------------------------------------------------------------
>>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-do-I-pass-a-value-obtained-in-%22Thread-Group-1%22-%28with-%22XPath-Extractor%22-from-a-%22WebService%28SOAP%29-Request%22%29-to-%22Thread-Group-2%22-for-use-as-input-to-%22WebService%28SOAP%29-Request%22-tp19683794p19753696.html
Sent from the JMeter - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: how do I pass a value obtained in "Thread Group 1" (with "XPath Extractor" from a "WebService(SOAP) Request") to "Thread Group 2" for use as input to "WebService(SOAP) Request"

Posted by sebb <se...@gmail.com>.
On 02/10/2008, sebb <se...@gmail.com> wrote:
> On 02/10/2008, Mark24 <mh...@infomedia.com.au> wrote:
>  >
>  >  My untrained eye cannot fault my test. Can anyone see where I've done
>  >  something wrong please?
>  >
>  >  Expected result: The console shows:
>  >  In First Thread: 417E9AFE-1690-DD11-8B26-005056C00008
>  >  In Second Thread: 417E9AFE-1690-DD11-8B26-005056C00008
>  >  In Second Thread Login: 417E9AFE-1690-DD11-8B26-005056C00008
>  >
>  >  Actual result:
>  >  In First Thread: 417E9AFE-1690-DD11-8B26-005056C00008
>  >
>  >  http://www.nabble.com/file/p19772782/11%2Bconsole%2Bresults.png
>  >  Above is the results seen in the console window from running the test (refer
>  >  to the last line in the screenshot; the previous 2 lines are experimental
>  >  runs with other print() statements in the BeanShell code)
>  >
>  >  Note that the log file reports that there is an error at print(bsh.args[0])
>
>
> And which thread group is running when this occurs? Line no, col no?
>
>  There must be an occurrence of print(bsh.args[0]) somewhere in the
>  test plan; search the JMX file for it.
>
>  This is presumably why Thread Group 2 does not show any output.
>
>
>  >  I expect property "securityid" to return the same value in Thread 1 as in
>  >  Thread 2 but clearly it doesn't.
>
>
> How do you know that?
>
>  There is no output showing the value, which is probably because of the
>  error in the log.
>
>  Looks to me like Thread Group 2 does not produce any output.
>
>  Instead of using BeanShell to show values, try using the Debug Sampler
>  - that's what it is for.
>
>
>  >  http://www.nabble.com/file/p19772782/1%2BTest.png
>  >  Above is the test
>  >
>  >  http://www.nabble.com/file/p19772782/2%2BTestPlan.png
>  >  Above is the test plan
>  >
>  >  http://www.nabble.com/file/p19772782/3%2BThread%2B1.png
>  >  Above is Thread 1
>
>
> Thread Group 1
>
>
>  >  http://www.nabble.com/file/p19772782/4%2BLogin%2528%2529.png
>  >  Above is Login()
>  >
>  >  http://www.nabble.com/file/p19772782/5%2BGet%2BtheID.png
>  >  Above is Get theID
>  >
>  >  http://www.nabble.com/file/p19772782/6%2BSet%2Band%2Bprint%2Bsecurityid.png
>  >  Above Set and print securityid
>
>
> Print statement would be safer as
>
>  print("In First Thread Group: ${__P(securityid)}");
>
>  Your statement only works because the property is enclosed in quotes.
>

Thanks for the test plan sent privately.

The setProperty statement below is wrong:

${__setProperty(securityid,bsh.args[0])};

Variables and functions are evaluated before they are passed to
BeanShell, so the script sees the return value from the function -
which is the empty string - and the property is set to "bsh.args[0]".

This is what causes the error in the print statements in the second
thread group.

Print works OK in the first thread group, because the print statement
resolves to:

print("In First Thread: " + bsh.args[0]);

bsh.args[0] is defined there; it is null in the second thread group,
which causes the error.
[You can see this by providing parameters in Thread Group 2]

This problem was quite easy to find using the Debug Sampler to show
the property values.

The simplest solution is to recode the setProperty as

${__setProperty(securityid,${theId}};

but this does not need BeanShell to execute - any sampler will do.

You also need to change the print statements in the scripts so that
any JMeter variable and function references are within quotes; only
BeanShell variables are valid outside the quotes.

The ${} references are replaced by their values *before* the script is
passed to BeanShell.

>  >  http://www.nabble.com/file/p19772782/7%2BThread%2B2.png
>  >  Above is Thread 2
>
>
> Thread Group 2
>
>
>  >  http://www.nabble.com/file/p19772782/8%2Bprint%2Bsecurityid.png
>  >  Above is print securityid
>
>
> See above.
>
>
>  >  http://www.nabble.com/file/p19772782/9%2BLogin%2528%2529.png
>  >  Above is Login()
>  >
>  >  http://www.nabble.com/file/p19772782/10%2Bprint%2Bsecurityid%2Bwithin%2BLogin%2528%2529.png
>  >  Above is print security within Login()
>  >
>
>
> Ditto.
>
>  It's impossible to debug the test fully from the screenshots.

In retrospect, that was wrong, but it's certainly easier with a script...

>  I will need to see the actual test plan. Just redact the sensitive
>  parts, and then send me a copy privately.
>
>  >
>  >
>  >
>  >
>  >  --
>
> >  View this message in context: http://www.nabble.com/how-do-I-pass-a-value-obtained-in-%22Thread-Group-1%22-%28with-%22XPath-Extractor%22-from-a-%22WebService%28SOAP%29-Request%22%29-to-%22Thread-Group-2%22-for-use-as-input-to-%22WebService%28SOAP%29-Request%22-tp19683794p19772782.html
>  >
>  > Sent from the JMeter - User mailing list archive at Nabble.com.
>  >
>  >
>  >  ---------------------------------------------------------------------
>  >  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  >  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >
>  >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: how do I pass a value obtained in "Thread Group 1" (with "XPath Extractor" from a "WebService(SOAP) Request") to "Thread Group 2" for use as input to "WebService(SOAP) Request"

Posted by sebb <se...@gmail.com>.
On 02/10/2008, Mark24 <mh...@infomedia.com.au> wrote:
>
>  My untrained eye cannot fault my test. Can anyone see where I've done
>  something wrong please?
>
>  Expected result: The console shows:
>  In First Thread: 417E9AFE-1690-DD11-8B26-005056C00008
>  In Second Thread: 417E9AFE-1690-DD11-8B26-005056C00008
>  In Second Thread Login: 417E9AFE-1690-DD11-8B26-005056C00008
>
>  Actual result:
>  In First Thread: 417E9AFE-1690-DD11-8B26-005056C00008
>
>  http://www.nabble.com/file/p19772782/11%2Bconsole%2Bresults.png
>  Above is the results seen in the console window from running the test (refer
>  to the last line in the screenshot; the previous 2 lines are experimental
>  runs with other print() statements in the BeanShell code)
>
>  Note that the log file reports that there is an error at print(bsh.args[0])

And which thread group is running when this occurs? Line no, col no?

There must be an occurrence of print(bsh.args[0]) somewhere in the
test plan; search the JMX file for it.

This is presumably why Thread Group 2 does not show any output.

>  I expect property "securityid" to return the same value in Thread 1 as in
>  Thread 2 but clearly it doesn't.

How do you know that?

There is no output showing the value, which is probably because of the
error in the log.

Looks to me like Thread Group 2 does not produce any output.

Instead of using BeanShell to show values, try using the Debug Sampler
- that's what it is for.

>  http://www.nabble.com/file/p19772782/1%2BTest.png
>  Above is the test
>
>  http://www.nabble.com/file/p19772782/2%2BTestPlan.png
>  Above is the test plan
>
>  http://www.nabble.com/file/p19772782/3%2BThread%2B1.png
>  Above is Thread 1

Thread Group 1

>  http://www.nabble.com/file/p19772782/4%2BLogin%2528%2529.png
>  Above is Login()
>
>  http://www.nabble.com/file/p19772782/5%2BGet%2BtheID.png
>  Above is Get theID
>
>  http://www.nabble.com/file/p19772782/6%2BSet%2Band%2Bprint%2Bsecurityid.png
>  Above Set and print securityid

Print statement would be safer as

print("In First Thread Group: ${__P(securityid)}");

Your statement only works because the property is enclosed in quotes.

>  http://www.nabble.com/file/p19772782/7%2BThread%2B2.png
>  Above is Thread 2

Thread Group 2

>  http://www.nabble.com/file/p19772782/8%2Bprint%2Bsecurityid.png
>  Above is print securityid

See above.

>  http://www.nabble.com/file/p19772782/9%2BLogin%2528%2529.png
>  Above is Login()
>
>  http://www.nabble.com/file/p19772782/10%2Bprint%2Bsecurityid%2Bwithin%2BLogin%2528%2529.png
>  Above is print security within Login()
>

Ditto.

It's impossible to debug the test fully from the screenshots.

I will need to see the actual test plan. Just redact the sensitive
parts, and then send me a copy privately.

>
>
>
>
>  --
>  View this message in context: http://www.nabble.com/how-do-I-pass-a-value-obtained-in-%22Thread-Group-1%22-%28with-%22XPath-Extractor%22-from-a-%22WebService%28SOAP%29-Request%22%29-to-%22Thread-Group-2%22-for-use-as-input-to-%22WebService%28SOAP%29-Request%22-tp19683794p19772782.html
>
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: how do I pass a value obtained in "Thread Group 1" (with "XPath Extractor" from a "WebService(SOAP) Request") to "Thread Group 2" for use as input to "WebService(SOAP) Request"

Posted by Mark24 <mh...@infomedia.com.au>.
My untrained eye cannot fault my test. Can anyone see where I've done
something wrong please?

Expected result: The console shows:
In First Thread: 417E9AFE-1690-DD11-8B26-005056C00008
In Second Thread: 417E9AFE-1690-DD11-8B26-005056C00008
In Second Thread Login: 417E9AFE-1690-DD11-8B26-005056C00008

Actual result: 
In First Thread: 417E9AFE-1690-DD11-8B26-005056C00008

http://www.nabble.com/file/p19772782/11%2Bconsole%2Bresults.png 
Above is the results seen in the console window from running the test (refer
to the last line in the screenshot; the previous 2 lines are experimental
runs with other print() statements in the BeanShell code)

Note that the log file reports that there is an error at print(bsh.args[0])


I expect property "securityid" to return the same value in Thread 1 as in
Thread 2 but clearly it doesn't.

http://www.nabble.com/file/p19772782/1%2BTest.png 
Above is the test

http://www.nabble.com/file/p19772782/2%2BTestPlan.png 
Above is the test plan

http://www.nabble.com/file/p19772782/3%2BThread%2B1.png 
Above is Thread 1

http://www.nabble.com/file/p19772782/4%2BLogin%2528%2529.png 
Above is Login()

http://www.nabble.com/file/p19772782/5%2BGet%2BtheID.png 
Above is Get theID

http://www.nabble.com/file/p19772782/6%2BSet%2Band%2Bprint%2Bsecurityid.png 
Above Set and print securityid

http://www.nabble.com/file/p19772782/7%2BThread%2B2.png 
Above is Thread 2

http://www.nabble.com/file/p19772782/8%2Bprint%2Bsecurityid.png 
Above is print securityid

http://www.nabble.com/file/p19772782/9%2BLogin%2528%2529.png 
Above is Login()

http://www.nabble.com/file/p19772782/10%2Bprint%2Bsecurityid%2Bwithin%2BLogin%2528%2529.png 
Above is print security within Login()





-- 
View this message in context: http://www.nabble.com/how-do-I-pass-a-value-obtained-in-%22Thread-Group-1%22-%28with-%22XPath-Extractor%22-from-a-%22WebService%28SOAP%29-Request%22%29-to-%22Thread-Group-2%22-for-use-as-input-to-%22WebService%28SOAP%29-Request%22-tp19683794p19772782.html
Sent from the JMeter - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: how do I pass a value obtained in "Thread Group 1" (with "XPath Extractor" from a "WebService(SOAP) Request") to "Thread Group 2" for use as input to "WebService(SOAP) Request"

Posted by sebb <se...@gmail.com>.
On 01/10/2008, Mark24 <mh...@infomedia.com.au> wrote:
>
>
>  From my observations it looks like if a parameter is set to a variable in
>  BeanShell PostProcessor i.e. ${__setProperty(parameterName,variableName)},

That is setting a property, not a variable.

>  printing the parameterName value to console i.e.
>  print(${__P(parameterName)}) works as expected (if variableName was declared
>  in BeanShell as: String variableName = "mary had a little lamb", it would
>  print "mary had a little lamb").
>
>  However, in BeanShell PostProcessor in a separate ThreadGroup
>  print(${__P(parameterName)}) causes an error because variableName doesn't
>  exist (not in scope I guess).

Properties *are* shared between threadgroups - they are global to the
JVM, so there must be an error in the test plan.

>  Setting parameterName to a literal eg. "quick brown fox" prints as expected
>  in both ThreadGroups.
>
>  I've come to the conclusion that ${__P(parameterName)} evaluates to the
>  variable variableName (parameterName is a pointer to the variable perhaps?)

No, it evaluates the property named parameterName - properties are not
the same as variables in JMeter:

http://jakarta.apache.org/jmeter/usermanual/test_plan.html#properties

>  and works in the initial ThreadGroup as variableName is within scope
>  containing value "mary had a little lamb" but doesn't work in the second
>  ThreadGroup as variableName is out now out of scope.

Must be a bug in the test plan

>  In a nutshell this is what I think is happening ("a <- b" means a request
>  value from b):
>
>
>  Initial ThreadGroup:
>  ${__P(parameterName)}  <- variableName <-  "mary had a little lamb"

I assume you mean propertyName.

>  Second ThreadGroup:
>  ${__P(parameterName)}  <- variableName <-  !!Error, variableName doesn't
>  exist here!!
>

I assume you mean propertyName.

>
>  This has really got me snookered passing values between ThreadGroups; I
>  don't have an initialisation file so it must be my code which is incorrect:

Yes, it is.

>  ThreadGroup1's
>
> ${__setProperty(securityid,bsh.args[0],true)};
>

Which will set the property "securityid" to the value "bsh.args[0]"
and return the value "bsh.args[0[".

If this is executed in a BeanShell script, the script will see the
value of the function call - i.e. "bsh.args[0]" - which is a BeanShell
variable that is defined if the parameter is defined.

So the script:

print(${__setProperty(securityid,bsh.args[0],true)});

is passed to BeanShell as

print(bsh.args[0]);

>
> Or
>
>  ThreadGroup2's
>  ${__P(securityid)};
>

Looks OK; it will return "bsh.args[0]".

>
>  Thanks guys,
>
> Mark
>
>
>
>
>  sebb-2-2 wrote:
>  >
>  > On 29/09/2008, Mark24 <mh...@infomedia.com.au> wrote:
>  >>
>  >>  Thanks Sebb. I've tried your suggestions but had hit another snag:
>  >>
>  >>  I call Jmeter at the command window by "Jmeter -Jsecurityid=123" to
>  >> create a
>  >>  parameter securityid with default value "123".
>  >>
>  >>
>  >>  + Test Plan
>  >>  ++ Thread Group1
>  >>  +++ WebService(SOAP) Request1
>  >>  ++++ XPath Extractor
>  >>  ++++ BeanShell PostProcessor1
>  >>
>  >>  ++ Thread Group2
>  >>  +++ WebService(SOAP) Request2
>  >>  ++++ BeanShell PostProcessor2
>  >>
>  >>
>  >>  In Thread Group1, XPath Extractor I set:
>  >>  - Reference Name = theSID
>  >>  - Xpath query = //sid
>  >>  - Default Value = "nomatchfound"
>  >>
>  >>  In Thread Group1, BeanShell PostProcessor1 I set:
>  >>  - Reset Interpreter = False
>  >>  - Parameters = ${theSID}
>  >>  - Script = ${__setProperty(securityid,bsh.args[0],true)};
>  >>  print(${__P(securityid)});
>  >>
>  >>
>  >>  In Thread Group2, BeanShell PostProcessor2 I set:
>  >>  - Reset Interpreter = False
>  >>  - Parameters =
>  >>  - Script = print(${__P(securityid)});
>  >>
>  >>
>  >>  I run this Test Plan, it extracts //sid (say, "123456", sets securityid
>  >> to
>  >>  "123456" and prints to console "123456" in BeanShell PostProcessor1, but
>  >> in
>  >>  Thread Group2's BeanShell PostProcessor2 it doesn't print to console but
>  >>  instead logs an error in jmeter.log mentioning "Error invoking bsh
>  >> method:
>  >>  eval Sourced file: inline evaluation of: ''print(bsh.args[0]);''"
>  >>
>  >>
>  >>  I expect print(${__P(securityid)}); in BeanShell PostProcessor2 to print
>  >>  "123456" but is looks like it is evaluating bsh.args[0] and because it
>  >>  doesn't exist here it errors out.
>  >>
>  >>  What am i doing wrong?
>  >
>  > Neither JMeter nor BeanShell will add ''print(bsh.args[0]);'' to the
>  > script by themselves, so there must be an error in your BeanShell
>  > script - or perhaps initialisation file.
>  >
>  >>
>  >>
>  >>
>  >>
>  >>  sebb-2-2 wrote:
>  >>  >
>  >>  > On 26/09/2008, Mark24 <mh...@infomedia.com.au> wrote:
>  >>  >>
>  >>  >>  Thanks for your reply sebb, you are very informative (i've been
>  >> reading
>  >>  >> your
>  >>  >>  answer to questions quite often over the last 3 days ive been using
>  >>  >> JMeter).
>  >>  >>
>  >>  >>  My grand plan is to regression test my company's MS web services by
>  >>  >> loging
>  >>  >>  in once to get the security id, then spawn multiple virtual users to
>  >>  >> work
>  >>  >>  together to call the other WS methods using a collection of inputs
>  >> from
>  >>  >> a
>  >>  >>  database. certain values from the responses are planned to be
>  >> inserted
>  >>  >> into
>  >>  >>  a database to later run some sql to compare these values against a
>  >> test
>  >>  >>  baseline database.
>  >>  >>
>  >>  >>  I was using one thread group which was spawning a single user to to
>  >> get
>  >>  >> the
>  >>  >>  security id, then the second thread group would spawn n virtual
>  >> users.
>  >>  >>
>  >>  >
>  >>  > OK, it was not clear that you wanted to use a single id in multiple
>  >>  > threads.
>  >>  >
>  >>  > In which case, use two thread groups, and set them to run one after
>  >>  > another.
>  >>  >
>  >>  > Extract the id you want to use, and save it as a JMeter Property using
>  >>  > the function:
>  >>  >
>  >>  >
>  >> http://jakarta.apache.org/jmeter/usermanual/functions.html#__setProperty
>  >>  >
>  >>  > You can then use the __P() function to retrieve the value in the
>  >>  > second thread group.
>  >>  >
>  >>  > Or if you already have a lot of samplers using a variable, just add a
>  >>  > user parameters pre-processor to the first one and copy the property
>  >>  > to the variable there.
>  >>  >
>  >>  >>  I'm possibly approaching the solution to my problem incorrectly so
>  >>  >> please
>  >>  >>  comment or point me to some reading material. My Jmeter textbook has
>  >>  >> been
>  >>  >>  order on Amazon but until then, the jmeter docs and forums like this
>  >> are
>  >>  >> my
>  >>  >>  friends.
>  >>  >
>  >>  > There's also quite a lot of information on the Wiki.
>  >>  >
>  >>  >>  Thanks again Sebb,
>  >>  >>
>  >>  >>  Mark
>  >>  >>
>  >>  >>
>  >>  >>  sebb-2-2 wrote:
>  >>  >>  >
>  >>  >>  > On 26/09/2008, Mark24 <mh...@infomedia.com.au> wrote:
>  >>  >>  >>
>  >>  >>  >>  In Jmeter 2.3.2, how do I pass a value obtained in "Thread Group
>  >> 1"
>  >>  >>  >> (with
>  >>  >>  >>  "XPath Extractor" from a "WebService(SOAP) Request") to "Thread
>  >>  >> Group 2"
>  >>  >>  >> for
>  >>  >>  >>  use as input to "WebService(SOAP) Request"
>  >>  >>  >>
>  >>  >>  >>  Graphically:
>  >>  >>  >>
>  >>  >>  >>  "Thread Group 1"
>  >>  >>  >>    "WebService(SOAP) Request"  //login() WS method which returns
>  >> a
>  >>  >>  >> security
>  >>  >>  >>  ID
>  >>  >>  >>    "XPath Extractor"  //extract security ID to security_ID
>  >> variable
>  >>  >>  >>  "Thread Group 2"
>  >>  >>  >>    "WebService(SOAP) Request"  //use ${security_ID} as a
>  >> parameter to
>  >>  >>  >> this
>  >>  >>  >>  Search() WS method
>  >>  >>  >>
>  >>  >>  >>
>  >>  >>  >>  Variable security_ID declared in "Thread Group 1"'s "XPath
>  >>  >> Extractor"
>  >>  >>  >> seems
>  >>  >>  >>  to be very narrowly scoped as "${security_ID}" is literally used
>  >> as
>  >>  >>  >> input to
>  >>  >>  >>  "Thread Group 2"'s "WebService(SOAP) Request" instead of the
>  >> value
>  >>  >> of
>  >>  >>  >>  ${security_ID}.
>  >>  >>  >>
>  >>  >>  >>  I've tried declaring the security_ID variable in "Test Plan to
>  >> use"
>  >>  >> but
>  >>  >>  >> this
>  >>  >>  >>  doesn't work (${security_ID} resolves to the value i set during
>  >>  >>  >> declaration
>  >>  >>  >>  instead of the extracted value).
>  >>  >>  >
>  >>  >>  > Why not use the same Thread Group for the two SOAP requests?
>  >>  >>  >
>  >>  >>  > e.g.
>  >>  >>  >
>  >>  >>  > Thread Group
>  >>  >>  > + SOAP
>  >>  >>  > + + XPath
>  >>  >>  > + SOAP using variable
>  >>  >>  >
>  >>  >>  > If you want to run multiple requests with the same variable, just
>  >> add
>  >>  >>  > them at the end, or enclose in a loop:
>  >>  >>  >
>  >>  >>  > Thread Group
>  >>  >>  > + SOAP
>  >>  >>  > + + XPath
>  >>  >>  > + Loop
>  >>  >>  > + + SOAP using variable
>  >>  >>  >
>  >>  >>  >>  Thanks for any help,
>  >>  >>  >>  Mark
>  >>  >>  >>
>  >>  >>  >>
>  >>  >>  >>  --
>  >>  >>  >>  View this message in context:
>  >>  >>  >>
>  >>  >>
>  >> http://www.nabble.com/how-do-I-pass-a-value-obtained-in-%22Thread-Group-1%22-%28with-%22XPath-Extractor%22-from-a-%22WebService%28SOAP%29-Request%22%29-to-%22Thread-Group-2%22-for-use-as-input-to-%22WebService%28SOAP%29-Request%22-tp19683794p19683794.html
>  >>  >>  >>  Sent from the JMeter - User mailing list archive at Nabble.com.
>  >>  >>  >>
>  >>  >>  >>
>  >>  >>  >>
>  >>  >> ---------------------------------------------------------------------
>  >>  >>  >>  To unsubscribe, e-mail:
>  >> jmeter-user-unsubscribe@jakarta.apache.org
>  >>  >>  >>  For additional commands, e-mail:
>  >> jmeter-user-help@jakarta.apache.org
>  >>  >>  >>
>  >>  >>  >>
>  >>  >>  >
>  >>  >>  >
>  >> ---------------------------------------------------------------------
>  >>  >>  > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  >>  >>  > For additional commands, e-mail:
>  >> jmeter-user-help@jakarta.apache.org
>  >>  >>  >
>  >>  >>  >
>  >>  >>  >
>  >>  >>
>  >>  >>
>  >>  >> --
>  >>  >>  View this message in context:
>  >>  >>
>  >> http://www.nabble.com/how-do-I-pass-a-value-obtained-in-%22Thread-Group-1%22-%28with-%22XPath-Extractor%22-from-a-%22WebService%28SOAP%29-Request%22%29-to-%22Thread-Group-2%22-for-use-as-input-to-%22WebService%28SOAP%29-Request%22-tp19683794p19686226.html
>  >>  >>
>  >>  >> Sent from the JMeter - User mailing list archive at Nabble.com.
>  >>  >>
>  >>  >>
>  >>  >>
>  >> ---------------------------------------------------------------------
>  >>  >>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  >>  >>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >>  >>
>  >>  >>
>  >>  >
>  >>  > ---------------------------------------------------------------------
>  >>  > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  >>  > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >>  >
>  >>  >
>  >>  >
>  >>
>  >>  --
>  >>
>  >> View this message in context:
>  >> http://www.nabble.com/how-do-I-pass-a-value-obtained-in-%22Thread-Group-1%22-%28with-%22XPath-Extractor%22-from-a-%22WebService%28SOAP%29-Request%22%29-to-%22Thread-Group-2%22-for-use-as-input-to-%22WebService%28SOAP%29-Request%22-tp19683794p19718151.html
>  >>
>  >> Sent from the JMeter - User mailing list archive at Nabble.com.
>  >>
>  >>
>  >>  ---------------------------------------------------------------------
>  >>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  >>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >>
>  >>
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >
>  >
>  >
>
>  --
>
> View this message in context: http://www.nabble.com/how-do-I-pass-a-value-obtained-in-%22Thread-Group-1%22-%28with-%22XPath-Extractor%22-from-a-%22WebService%28SOAP%29-Request%22%29-to-%22Thread-Group-2%22-for-use-as-input-to-%22WebService%28SOAP%29-Request%22-tp19683794p19753696.html
>
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org