Forum Discussion

Liberty_Informa's avatar
Liberty_Informa
Regular Contributor
14 years ago

custom Properties for Object

Hi,

We understand that script runs in a defined scope.

In the Project load script, we retrieve variable called config something like:

def config = new ConfigSlurper().parse(new File(projectPath + "/xyz.properties").toURL())

Can't we pass 'config' object to all test cases to read further from property file?

definitely project.setPropertyValue ("config", config) will not work, context.setProperty ("config", config) will work, but you get context as null in the test case level.

Anything better to work with this?

3 Replies

  • Hi,

    project/testsuite/testcase properties are stored as strings - so saving an object like this won't work - you could create a singleton class in your Script Library that you initialize in the load script and access from other scripts as required.

    Hope this helps!

    /Ole
    SmartBear Software
  • Liberty_Informa's avatar
    Liberty_Informa
    Regular Contributor
    One of the forum members, M. McDonanld provided alternate solution, which is easy.

    He suggests to retrieve property file object as -


    project.metaClass.config = new ConfigSlurper().parse(new File(projectPath + "/<propertyFileName>.properties").toURL())


    and further use property file values like -


    project.setPropertyValue ("<propertyName>" , project.config.<key> as String)
    log.info "Property value: " +project.getPropertyValue("<propertyName>")