Forum Discussion

ian_howard's avatar
ian_howard
New Contributor
15 years ago

Accessing TestSuite an Project level properties from Groovy

I am able to access anything in a testCase from Groovy, but I am having difficulty with the syntax for accessing TestSuite and Project level properties.

So for Project X,with Test Property P1 what is the groovy syntax necessary for getting the value of this property from within TestSuite Y, TestCase Z?

Similarly for accessing a Property T1 inTest Suite Y from Test Case Z?

4 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    If you're just interested in reading the values of properties, you should use Property Expansions, like


    context.expand('${#Project#P1}')


    (note the required use of single quotes). If you need write access, or need to access properties in another TestSuite or TestCase, you will need to access the properties "manually" For example:


    //Access property 'C1' in current TestCase:
    def property = testRunner.testCase.properties['C1']

    //Access property 'T1' in current TestSuite:
    def property = testRunner.testCase.testSuite.properties['T1']

    //Access property 'T2' in TestSuite 'TS2' (which is different from the current TestSuite):
    def property = testRunner.testCase.testSuite.project.testSuites['TS2'].properties['T2']

    //Once you have a reference to the property you can read or write the value:
    property.value = 'new value'
    log.info property.value



    Regards,
    Dain
    eviware.com
  • Heaven's avatar
    Heaven
    Occasional Contributor
    Hi
    this is another way to change the property of test suite

    // this is the script to change/ set the properties of
    // any of the test suite in same project


    testRunner.testCase.testSuite.project.testSuites["TestSuite name"].
     
      setPropertyValue( "property name", "property value" )
  • grexe's avatar
    grexe
    Occasional Contributor
    (Couldn't reply to the more appropriate thread about project properties not expanded in Groovy scripts)

    I had no luck with expanding project properties like [tt:1cglnrmn]${projectDir}[/tt:1cglnrmn] in a TestCase's groovy script.
    Instead, I had to manually define a project property that holds [tt:1cglnrmn]${projectDir}[/tt:1cglnrmn] - only then it worked.