You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by Sonam Chauhan <so...@ce.com.au> on 2003/12/24 05:02:42 UTC

Problem initializing JMeter variables - Was "How can I add a JMeter property in code"

I tried this code earlier for setting JMeter variable (say, '${var}'
--------------
public void modifyTestElement(TestElement el)
{
	el.setProperty(
         new StringProperty("var","REPLACED"));
--------------

Since that didn't work, I tried manipulating the context (saw this type
of coding in RegexExtractor.java):
--------------
public void modifyTestElement(TestElement el)
{
	JMeterVariables jmv = new JMeterVariables();
	jmv.put("var", "REPLACED");
	JMeterContext context = 
		JMeterContextService.getContext();
	context.setVariables(jmv);
--------------

It didn't work either. "${var}" stays un-substituted. 

If someone could help, that would be great - the Javadoc and the
extension documentation isn't descriptive enough. 

With regards,
Sonam Chauhan
-- 
Corporate Express Australia Ltd.
Phone: +61-2-9335-0725, Fax: 9335-0753, Email: sonamc@ce.com.au
 

> -----Original Message-----
> From: Sonam Chauhan [mailto:sonam.chauhan@ce.com.au]
> Sent: Wednesday, 24 December 2003 11:10 AM
> To: 'jmeter-dev@jakarta.apache.org'
> Subject: How can I add a JMeter property in code
> 
> Hello JMeter developers - I am trying to create a JMeter config
element
> that
> automatically initialize "JMeter variables" (not sure if this is the
> correct
> term) from Java properties.
> 
> E.g.: If the properties were passed into JMeter at runtime:
> 	ce.debug=...
> 	ce.cxml.user1=...
> 	ce.cxml.pass1=...
> 	ce.oci.user1=...
> ...the new 'LoadPropertiesElement' element could take the string "ce"
as
> it's input, then automatically initializes JMeter variables based on
the
> ce*
> properties:
> 	${ce.debug}
> 	${ce.cxml.user1}
> 	${ce.cxml.pass1}
> 	${ce.oci.user1}
> These variables can then be used in the test plan.
> 
> I created a new LoadPropertiesElement (extends AbstractTestElement)
and
> LoadPropertiesElementGui (extends AbstractConfigGui) and got it
running.
> However, I have run into problems setting the 'JMeter variables' in
> LoadPropertiesElementGui.modifyTestElement(). Here is some debug code:
> ---------------------------------------------------------------
>     public void modifyTestElement(TestElement el)
>     {
>      	super.configureTestElement(el);
> 	Properties p  = System.getProperties();
> 	Enumeration e = p.propertyNames();
> 	while (e.hasMoreElements()) {
> 		String propName = (String) e.nextElement();
> 		if (propName.startsWith("java")) {
> 			System.out.println(propName);
> 			System.out.println("---------------------");
> 
> 			//  >>>Does not work!? <<<
> 			el.setProperty(propName,
.getProperty(propName));
> 		}
> 	}
>     }
> ---------------------------------------------------------------
> 
> Is what I am doing above the correct way to set 'JMeter variables'?
When
> the
> code runs, the 'java.home' property name is printed to stdout, but
> ${java.home} stays unsubstituted.
> 
> With regards,
> Sonam Chauhan
> --
> Corporate Express Australia Ltd.
> Phone: +61-2-9335-0725, Fax: 9335-0753, Email: sonamc@ce.com.au
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org


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


Re: Problem initializing JMeter variables - Was "How can I add a JMeter property in code"

Posted by Jordi Salvat i Alabart <js...@atg.com>.
You're absolutely right: the developer documentation is absolutely 
insufficient.

The change you want to do probably requires changes in the JMeter 
engine. I created a "User Defined Variables" element to define variables 
outside of the Test Plan and that's what I had to do. I'm attaching the 
CVS message for my changes for your reference. If you use latest CVS 
code, you may be able to subclass my component in some way...

Good luck,

Jordi.


En/na Sonam Chauhan ha escrit:
> I tried this code earlier for setting JMeter variable (say, '${var}'
> --------------
> public void modifyTestElement(TestElement el)
> {
> 	el.setProperty(
>          new StringProperty("var","REPLACED"));
> --------------
> 
> Since that didn't work, I tried manipulating the context (saw this type
> of coding in RegexExtractor.java):
> --------------
> public void modifyTestElement(TestElement el)
> {
> 	JMeterVariables jmv = new JMeterVariables();
> 	jmv.put("var", "REPLACED");
> 	JMeterContext context = 
> 		JMeterContextService.getContext();
> 	context.setVariables(jmv);
> --------------
> 
> It didn't work either. "${var}" stays un-substituted. 
> 
> If someone could help, that would be great - the Javadoc and the
> extension documentation isn't descriptive enough. 
> 
> With regards,
> Sonam Chauhan