Forum Discussion

rdebie's avatar
rdebie
Contributor
17 years ago

fill properties step from file

I have 1 question.
When i fill the properties step from a groovy scrip.
(Just as your example in the help).

Do i have to see some changes in the properties step,
or do i load the Item in memory??

Regards,

Raymond

3 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Raymond,

    how do you mean? You should see the assigned property values in the PropertiesStep editor.. you need to be sure that the properties exist or you will need to add them first (before assigning them a value) with

    def propertiesStep = testRunner.testCase.getTestStepByName( "..." )
    propertiesStep.addProperty( "myProperty" )
    propertiesStep.setPropertyValue( "myProperty", ... )

    Hope this helps!

    regards,

    /Ole
    eviware.com
  • I ask this, because when i use the script below, the properties where not added.

    // read the file
    def properties = new java.util.Properties();
    properties.load( new java.io.FileInputStream( "testprops.txt" ));

    def targetStep = testRunner.testCase.getTestStepByName( "Properties" );

    // assign single property
    targetStep.setPropertyValue( "myproperty", properties.getProperty( "myproperty" ));

    // assign all properties
    def names = properties.propertyNames();
    while( names.hasMoreElements() )
    {
      def name = names.nextElement();
      targetStep.setPropertyValue( name, properties.getProperty( name ));
    }


    This is a script from the manual.
    http://www.soapui.org/userguide/functio ... t_Examples
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    Yes, this script requires that the properties in the file have already been defined in the properties step (which could be clarified in the docs..)

    You can modify the script as follows to ensure creation of missing properties:

    ...
    while( names.hasMoreElements() )
    {
      def name = names.nextElement();
      if( targetStep.getProperty( name ) == null )
          targetStep.addProperty( name )

      targetStep.setPropertyValue( name, properties.getProperty( name ));
    }
    ...

    Hope this helps!

    regards,

    /Ole
    eviware.com