Forum Discussion

zsousa's avatar
zsousa
Contributor
8 years ago
Solved

check if custom property exists

Hi All, I have a test case that has several custom properties, is there a way to check if a specific custom property exists ?

  • Yes, here is a sample of code using a GroovyScript teststep and the testRunner variable,

     

    hasProperty is the method to find out if the property exists.

    This code sees if a property exists and deletes the property if it is found, so that it can be set by another groovy script.

     

    def tc = testRunner.getTestCase()
    if (tc.hasProperty("myCustomProperty")) tc.removeProperty( "myCustomProperty" )

     

    Hope it helps

     

     

3 Replies

  • zen_paul's avatar
    zen_paul
    Occasional Contributor

    Yes, here is a sample of code using a GroovyScript teststep and the testRunner variable,

     

    hasProperty is the method to find out if the property exists.

    This code sees if a property exists and deletes the property if it is found, so that it can be set by another groovy script.

     

    def tc = testRunner.getTestCase()
    if (tc.hasProperty("myCustomProperty")) tc.removeProperty( "myCustomProperty" )

     

    Hope it helps

     

     

  • nmrao's avatar
    nmrao
    Champion Level 3
    Yes, use groovy script to do the same. What is your use case?