You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Pravesh Prajapati <pr...@gmail.com> on 2015/07/19 14:15:38 UTC

How to use shared variables in Jmeter.

Hi team

1. I have 2 scripts and I am executing both sane time.
now the case is that my script-1 is generating policy no and I want to pass
this policy no in script 2 at run time not by parameterization.
Is this is possibel in jmeter.

Can we store the generated policy number at run time & pass it to second
script.


-- 
Regards,
Pravesh prajapati.
Mob:-9702600170

Re: How to use shared variables in Jmeter.

Posted by Deepak Shetty <sh...@gmail.com>.
Hi
>As scenerios are different, we cannot create same scripts.
thats not a JMeter limitation - Jmeter allows you to
a) Do everything in the same thread group - but distribute the way the
scenarios are executed using various controller
b) Use different thread groups in the same test plan for different scenarios
c) Include different JMX files using Include Controller in one test plan
(also can use modules within the same test plan to keep scenarios as
logically distinct)
It is not uncommon for e.g. to have the same JMX file run a scenario as a
user(place order, policy) and as an admin(approve order,policy) by using
any of the technique above. Your organisation as such may have a coding
policy that prevents you from doing this (and sometimes you need to ask
why?)

One more thing to consider
You havent described your usecase - but possibly its something like Script
1 - user creates a policy. Script 2 admin type user has to approve it / act
on it.
If your application for e.g. has a UI where the admin type of user logs in
, then sees a list of policies that have been created and then can act on
them - you dont need to pass the policy number to be passed from Script 1
to Script 2 - because if you modify your script , you can read this number
dynamically from your web screens. If for e.g. admin user gets sent an
email - then that too can be dynamically obtained (by reading the email
from the mailbox) - as before depends on your particular application so im
not sure if it applies for whatever you are trying to do.

regards
deepak



regards
deepak


On Tue, Jul 21, 2015 at 9:04 AM, Pravesh Prajapati <
prajapati.pravesh@gmail.com> wrote:

> Hi Deepak,
> Thanks for quick reply.
> As scenerios are different, we cannot create same scripts.
>
> On Mon, Jul 20, 2015 at 11:27 AM, Deepak Shetty <sh...@gmail.com> wrote:
>
> > Also one of the things to ask at about this time is , is it worth it ? If
> > the scripts are really linked , then why not run it as part of the same
> > JMeter test (in which case sharing data is a little easier) ?
> >
> > regards
> > deepak
> >
> > On Mon, Jul 20, 2015 at 10:55 AM, Deepak Shetty <sh...@gmail.com>
> wrote:
> >
> > > Hi
> > > I'm assuming you have easy access to a DB that you can use for your
> test
> > > (if you dont and have some other shared resource then use that).
> > > In Script 1 - use a Listener to write the data to a table(You can use a
> > > JSR 223 Listener or a Backend Listener) . You could even use a JDBC
> > sampler
> > > to do this if you dont mind it showing in your test results.
> > > In script 2 - you have to first read from the same location(table) that
> > > you have written to. and use the returned data in your script.
> > > OR
> > > If Script1's result .jtl file is accessible to script 2 , then you can
> do
> > > the same by writing the variables to the file in Script1 (using
> > > sample_variables in jmeter.properties) and then reading the same file
> > from
> > > script 2 (and keeping track of where you are in the file.
> > > OR
> > > For every policy number in Script 1 , write it to a new file (using
> > > SimpleDatawriter) - In script 2 read all the files in the directory you
> > are
> > > writing to find out policy number
> > >
> > > Since you aren't giving much details on how you expect the two scripts
> to
> > > interact , theres not much more I can probably say.
> > >
> > > regards
> > > deepak
> > >
> > >
> > > On Sun, Jul 19, 2015 at 10:13 PM, Pravesh Prajapati <
> > > prajapati.pravesh@gmail.com> wrote:
> > >
> > >> Hi Deepak.
> > >> Thanks for your quick reply.
> > >> can you share me with the steps or component of jmeter which I can use
> > for
> > >> creating producer consumer system.
> > >>
> > >> Regards
> > >> pravesh.
> > >>
> > >>
> > >> On Monday, July 20, 2015, Deepak Shetty <sh...@gmail.com> wrote:
> > >>
> > >> > Hi
> > >> > >Can we store the generated policy number at run time & pass it to
> > >> second
> > >> > script.
> > >> > In general you can achieve this.
> > >> > Im assuming you mean Two separate Jmeter scripts running as two
> > separate
> > >> > JMeter instances i.e. two separate processes. (If you mean two
> > separate
> > >> > thread groups or two separate threads within the same JMeter, you
> can
> > >> get
> > >> > an easier answer).
> > >> > You can't *pass* data in the sense you probably mean - However you
> can
> > >> have
> > >> > one of the scripts write to a shared resource and you can have the
> > other
> > >> > script read from the shared resource. A shared resource that easily
> > lets
> > >> > you do this is any Database (though you can use anything that is
> > shared
> > >> and
> > >> > accessible via a different process - even files, or JMS or ) - so
> > you'd
> > >> > just create a table and write data using one JMeter script listener
> > and
> > >> > read it from the other one - You get a few NoSQL stores that perform
> > >> quite
> > >> > well too if thats a concern.
> > >> > You do have to solve your problems typical in this kind of Consumer
> -
> > >> > Producer systems (What if the Consumer is too fast /slow . Does a
> > >> producer
> > >> > need to be linked to particular consumer etc) - but that depends on
> > your
> > >> > use case
> > >> >
> > >> > regards
> > >> > deepak
> > >> >
> > >> >
> > >> > On Sun, Jul 19, 2015 at 5:15 AM, Pravesh Prajapati <
> > >> > prajapati.pravesh@gmail.com <javascript:;>> wrote:
> > >> >
> > >> > > Hi team
> > >> > >
> > >> > > 1. I have 2 scripts and I am executing both sane time.
> > >> > > now the case is that my script-1 is generating policy no and I
> want
> > to
> > >> > pass
> > >> > > this policy no in script 2 at run time not by parameterization.
> > >> > > Is this is possibel in jmeter.
> > >> > >
> > >> > > Can we store the generated policy number at run time & pass it to
> > >> second
> > >> > > script.
> > >> > >
> > >> > >
> > >> > > --
> > >> > > Regards,
> > >> > > Pravesh prajapati.
> > >> > > Mob:-9702600170
> > >> > >
> > >> >
> > >>
> > >>
> > >> --
> > >> Regards,
> > >> Pravesh prajapati.
> > >> Mob:-9702600170
> > >>
> > >
> > >
> >
>
>
>
> --
> Regards,
> Pravesh prajapati.
> Mob:-9702600170
>

Re: How to use shared variables in Jmeter.

Posted by Pravesh Prajapati <pr...@gmail.com>.
Hi Deepak,
Thanks for quick reply.
As scenerios are different, we cannot create same scripts.

On Mon, Jul 20, 2015 at 11:27 AM, Deepak Shetty <sh...@gmail.com> wrote:

> Also one of the things to ask at about this time is , is it worth it ? If
> the scripts are really linked , then why not run it as part of the same
> JMeter test (in which case sharing data is a little easier) ?
>
> regards
> deepak
>
> On Mon, Jul 20, 2015 at 10:55 AM, Deepak Shetty <sh...@gmail.com> wrote:
>
> > Hi
> > I'm assuming you have easy access to a DB that you can use for your test
> > (if you dont and have some other shared resource then use that).
> > In Script 1 - use a Listener to write the data to a table(You can use a
> > JSR 223 Listener or a Backend Listener) . You could even use a JDBC
> sampler
> > to do this if you dont mind it showing in your test results.
> > In script 2 - you have to first read from the same location(table) that
> > you have written to. and use the returned data in your script.
> > OR
> > If Script1's result .jtl file is accessible to script 2 , then you can do
> > the same by writing the variables to the file in Script1 (using
> > sample_variables in jmeter.properties) and then reading the same file
> from
> > script 2 (and keeping track of where you are in the file.
> > OR
> > For every policy number in Script 1 , write it to a new file (using
> > SimpleDatawriter) - In script 2 read all the files in the directory you
> are
> > writing to find out policy number
> >
> > Since you aren't giving much details on how you expect the two scripts to
> > interact , theres not much more I can probably say.
> >
> > regards
> > deepak
> >
> >
> > On Sun, Jul 19, 2015 at 10:13 PM, Pravesh Prajapati <
> > prajapati.pravesh@gmail.com> wrote:
> >
> >> Hi Deepak.
> >> Thanks for your quick reply.
> >> can you share me with the steps or component of jmeter which I can use
> for
> >> creating producer consumer system.
> >>
> >> Regards
> >> pravesh.
> >>
> >>
> >> On Monday, July 20, 2015, Deepak Shetty <sh...@gmail.com> wrote:
> >>
> >> > Hi
> >> > >Can we store the generated policy number at run time & pass it to
> >> second
> >> > script.
> >> > In general you can achieve this.
> >> > Im assuming you mean Two separate Jmeter scripts running as two
> separate
> >> > JMeter instances i.e. two separate processes. (If you mean two
> separate
> >> > thread groups or two separate threads within the same JMeter, you can
> >> get
> >> > an easier answer).
> >> > You can't *pass* data in the sense you probably mean - However you can
> >> have
> >> > one of the scripts write to a shared resource and you can have the
> other
> >> > script read from the shared resource. A shared resource that easily
> lets
> >> > you do this is any Database (though you can use anything that is
> shared
> >> and
> >> > accessible via a different process - even files, or JMS or ) - so
> you'd
> >> > just create a table and write data using one JMeter script listener
> and
> >> > read it from the other one - You get a few NoSQL stores that perform
> >> quite
> >> > well too if thats a concern.
> >> > You do have to solve your problems typical in this kind of Consumer -
> >> > Producer systems (What if the Consumer is too fast /slow . Does a
> >> producer
> >> > need to be linked to particular consumer etc) - but that depends on
> your
> >> > use case
> >> >
> >> > regards
> >> > deepak
> >> >
> >> >
> >> > On Sun, Jul 19, 2015 at 5:15 AM, Pravesh Prajapati <
> >> > prajapati.pravesh@gmail.com <javascript:;>> wrote:
> >> >
> >> > > Hi team
> >> > >
> >> > > 1. I have 2 scripts and I am executing both sane time.
> >> > > now the case is that my script-1 is generating policy no and I want
> to
> >> > pass
> >> > > this policy no in script 2 at run time not by parameterization.
> >> > > Is this is possibel in jmeter.
> >> > >
> >> > > Can we store the generated policy number at run time & pass it to
> >> second
> >> > > script.
> >> > >
> >> > >
> >> > > --
> >> > > Regards,
> >> > > Pravesh prajapati.
> >> > > Mob:-9702600170
> >> > >
> >> >
> >>
> >>
> >> --
> >> Regards,
> >> Pravesh prajapati.
> >> Mob:-9702600170
> >>
> >
> >
>



-- 
Regards,
Pravesh prajapati.
Mob:-9702600170

Re: How to use shared variables in Jmeter.

Posted by Deepak Shetty <sh...@gmail.com>.
Also one of the things to ask at about this time is , is it worth it ? If
the scripts are really linked , then why not run it as part of the same
JMeter test (in which case sharing data is a little easier) ?

regards
deepak

On Mon, Jul 20, 2015 at 10:55 AM, Deepak Shetty <sh...@gmail.com> wrote:

> Hi
> I'm assuming you have easy access to a DB that you can use for your test
> (if you dont and have some other shared resource then use that).
> In Script 1 - use a Listener to write the data to a table(You can use a
> JSR 223 Listener or a Backend Listener) . You could even use a JDBC sampler
> to do this if you dont mind it showing in your test results.
> In script 2 - you have to first read from the same location(table) that
> you have written to. and use the returned data in your script.
> OR
> If Script1's result .jtl file is accessible to script 2 , then you can do
> the same by writing the variables to the file in Script1 (using
> sample_variables in jmeter.properties) and then reading the same file from
> script 2 (and keeping track of where you are in the file.
> OR
> For every policy number in Script 1 , write it to a new file (using
> SimpleDatawriter) - In script 2 read all the files in the directory you are
> writing to find out policy number
>
> Since you aren't giving much details on how you expect the two scripts to
> interact , theres not much more I can probably say.
>
> regards
> deepak
>
>
> On Sun, Jul 19, 2015 at 10:13 PM, Pravesh Prajapati <
> prajapati.pravesh@gmail.com> wrote:
>
>> Hi Deepak.
>> Thanks for your quick reply.
>> can you share me with the steps or component of jmeter which I can use for
>> creating producer consumer system.
>>
>> Regards
>> pravesh.
>>
>>
>> On Monday, July 20, 2015, Deepak Shetty <sh...@gmail.com> wrote:
>>
>> > Hi
>> > >Can we store the generated policy number at run time & pass it to
>> second
>> > script.
>> > In general you can achieve this.
>> > Im assuming you mean Two separate Jmeter scripts running as two separate
>> > JMeter instances i.e. two separate processes. (If you mean two separate
>> > thread groups or two separate threads within the same JMeter, you can
>> get
>> > an easier answer).
>> > You can't *pass* data in the sense you probably mean - However you can
>> have
>> > one of the scripts write to a shared resource and you can have the other
>> > script read from the shared resource. A shared resource that easily lets
>> > you do this is any Database (though you can use anything that is shared
>> and
>> > accessible via a different process - even files, or JMS or ) - so you'd
>> > just create a table and write data using one JMeter script listener and
>> > read it from the other one - You get a few NoSQL stores that perform
>> quite
>> > well too if thats a concern.
>> > You do have to solve your problems typical in this kind of Consumer -
>> > Producer systems (What if the Consumer is too fast /slow . Does a
>> producer
>> > need to be linked to particular consumer etc) - but that depends on your
>> > use case
>> >
>> > regards
>> > deepak
>> >
>> >
>> > On Sun, Jul 19, 2015 at 5:15 AM, Pravesh Prajapati <
>> > prajapati.pravesh@gmail.com <javascript:;>> wrote:
>> >
>> > > Hi team
>> > >
>> > > 1. I have 2 scripts and I am executing both sane time.
>> > > now the case is that my script-1 is generating policy no and I want to
>> > pass
>> > > this policy no in script 2 at run time not by parameterization.
>> > > Is this is possibel in jmeter.
>> > >
>> > > Can we store the generated policy number at run time & pass it to
>> second
>> > > script.
>> > >
>> > >
>> > > --
>> > > Regards,
>> > > Pravesh prajapati.
>> > > Mob:-9702600170
>> > >
>> >
>>
>>
>> --
>> Regards,
>> Pravesh prajapati.
>> Mob:-9702600170
>>
>
>

Re: How to use shared variables in Jmeter.

Posted by Deepak Shetty <sh...@gmail.com>.
Hi
I'm assuming you have easy access to a DB that you can use for your test
(if you dont and have some other shared resource then use that).
In Script 1 - use a Listener to write the data to a table(You can use a JSR
223 Listener or a Backend Listener) . You could even use a JDBC sampler to
do this if you dont mind it showing in your test results.
In script 2 - you have to first read from the same location(table) that you
have written to. and use the returned data in your script.
OR
If Script1's result .jtl file is accessible to script 2 , then you can do
the same by writing the variables to the file in Script1 (using
sample_variables in jmeter.properties) and then reading the same file from
script 2 (and keeping track of where you are in the file.
OR
For every policy number in Script 1 , write it to a new file (using
SimpleDatawriter) - In script 2 read all the files in the directory you are
writing to find out policy number

Since you aren't giving much details on how you expect the two scripts to
interact , theres not much more I can probably say.

regards
deepak


On Sun, Jul 19, 2015 at 10:13 PM, Pravesh Prajapati <
prajapati.pravesh@gmail.com> wrote:

> Hi Deepak.
> Thanks for your quick reply.
> can you share me with the steps or component of jmeter which I can use for
> creating producer consumer system.
>
> Regards
> pravesh.
>
>
> On Monday, July 20, 2015, Deepak Shetty <sh...@gmail.com> wrote:
>
> > Hi
> > >Can we store the generated policy number at run time & pass it to second
> > script.
> > In general you can achieve this.
> > Im assuming you mean Two separate Jmeter scripts running as two separate
> > JMeter instances i.e. two separate processes. (If you mean two separate
> > thread groups or two separate threads within the same JMeter, you can get
> > an easier answer).
> > You can't *pass* data in the sense you probably mean - However you can
> have
> > one of the scripts write to a shared resource and you can have the other
> > script read from the shared resource. A shared resource that easily lets
> > you do this is any Database (though you can use anything that is shared
> and
> > accessible via a different process - even files, or JMS or ) - so you'd
> > just create a table and write data using one JMeter script listener and
> > read it from the other one - You get a few NoSQL stores that perform
> quite
> > well too if thats a concern.
> > You do have to solve your problems typical in this kind of Consumer -
> > Producer systems (What if the Consumer is too fast /slow . Does a
> producer
> > need to be linked to particular consumer etc) - but that depends on your
> > use case
> >
> > regards
> > deepak
> >
> >
> > On Sun, Jul 19, 2015 at 5:15 AM, Pravesh Prajapati <
> > prajapati.pravesh@gmail.com <javascript:;>> wrote:
> >
> > > Hi team
> > >
> > > 1. I have 2 scripts and I am executing both sane time.
> > > now the case is that my script-1 is generating policy no and I want to
> > pass
> > > this policy no in script 2 at run time not by parameterization.
> > > Is this is possibel in jmeter.
> > >
> > > Can we store the generated policy number at run time & pass it to
> second
> > > script.
> > >
> > >
> > > --
> > > Regards,
> > > Pravesh prajapati.
> > > Mob:-9702600170
> > >
> >
>
>
> --
> Regards,
> Pravesh prajapati.
> Mob:-9702600170
>

Re: How to use shared variables in Jmeter.

Posted by Pravesh Prajapati <pr...@gmail.com>.
Hi Deepak.
Thanks for your quick reply.
can you share me with the steps or component of jmeter which I can use for
creating producer consumer system.

Regards
pravesh.


On Monday, July 20, 2015, Deepak Shetty <sh...@gmail.com> wrote:

> Hi
> >Can we store the generated policy number at run time & pass it to second
> script.
> In general you can achieve this.
> Im assuming you mean Two separate Jmeter scripts running as two separate
> JMeter instances i.e. two separate processes. (If you mean two separate
> thread groups or two separate threads within the same JMeter, you can get
> an easier answer).
> You can't *pass* data in the sense you probably mean - However you can have
> one of the scripts write to a shared resource and you can have the other
> script read from the shared resource. A shared resource that easily lets
> you do this is any Database (though you can use anything that is shared and
> accessible via a different process - even files, or JMS or ) - so you'd
> just create a table and write data using one JMeter script listener and
> read it from the other one - You get a few NoSQL stores that perform quite
> well too if thats a concern.
> You do have to solve your problems typical in this kind of Consumer -
> Producer systems (What if the Consumer is too fast /slow . Does a producer
> need to be linked to particular consumer etc) - but that depends on your
> use case
>
> regards
> deepak
>
>
> On Sun, Jul 19, 2015 at 5:15 AM, Pravesh Prajapati <
> prajapati.pravesh@gmail.com <javascript:;>> wrote:
>
> > Hi team
> >
> > 1. I have 2 scripts and I am executing both sane time.
> > now the case is that my script-1 is generating policy no and I want to
> pass
> > this policy no in script 2 at run time not by parameterization.
> > Is this is possibel in jmeter.
> >
> > Can we store the generated policy number at run time & pass it to second
> > script.
> >
> >
> > --
> > Regards,
> > Pravesh prajapati.
> > Mob:-9702600170
> >
>


-- 
Regards,
Pravesh prajapati.
Mob:-9702600170

Re: How to use shared variables in Jmeter.

Posted by Deepak Shetty <sh...@gmail.com>.
Hi
>Can we store the generated policy number at run time & pass it to second
script.
In general you can achieve this.
Im assuming you mean Two separate Jmeter scripts running as two separate
JMeter instances i.e. two separate processes. (If you mean two separate
thread groups or two separate threads within the same JMeter, you can get
an easier answer).
You can't *pass* data in the sense you probably mean - However you can have
one of the scripts write to a shared resource and you can have the other
script read from the shared resource. A shared resource that easily lets
you do this is any Database (though you can use anything that is shared and
accessible via a different process - even files, or JMS or ) - so you'd
just create a table and write data using one JMeter script listener and
read it from the other one - You get a few NoSQL stores that perform quite
well too if thats a concern.
You do have to solve your problems typical in this kind of Consumer -
Producer systems (What if the Consumer is too fast /slow . Does a producer
need to be linked to particular consumer etc) - but that depends on your
use case

regards
deepak


On Sun, Jul 19, 2015 at 5:15 AM, Pravesh Prajapati <
prajapati.pravesh@gmail.com> wrote:

> Hi team
>
> 1. I have 2 scripts and I am executing both sane time.
> now the case is that my script-1 is generating policy no and I want to pass
> this policy no in script 2 at run time not by parameterization.
> Is this is possibel in jmeter.
>
> Can we store the generated policy number at run time & pass it to second
> script.
>
>
> --
> Regards,
> Pravesh prajapati.
> Mob:-9702600170
>