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: [EMAIL PROTECTED]
 

> -----Original Message-----
> From: Sonam Chauhan [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, 24 December 2003 11:10 AM
> To: '[EMAIL PROTECTED]'
> 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: [EMAIL PROTECTED]
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to