Forum Discussion

nkuno's avatar
nkuno
New Contributor
7 years ago
Solved

How to create a property using groovy script???

Hi Team,

 

In my automation script i am in need to create a property and store the value dynamically ,so that the value stored is used in upcoming steps for further process,Could anyone help in this.

 

I tried online every article says on set and get property in groovy,but i need to create a property in groovy.

 

  • Building on sanj's reply, depending on how you need to access the property there may be a few considerations you need to make.

     

    • If you need a property available across all test steps in a test case, store it at that test case level.
      • def testCaseProperty = testRunner.testCase.setPropertyValue("myTest", "blah")
      • (as provided by sanj)
    • If you need a property available across all test cases in a test suite, store it at the test suite level.
      • def testSuiteProperty = testRunner.testCase.testSuite.setPropertyValue("myTest", "blah")
    • If you need a property available across all test suites in a project, store it at the project level.
      • def projectProperty = testRunner.testCase.testSuite.project.setPropertyValue("myTest", "blah")

4 Replies

    • groovyguy's avatar
      groovyguy
      Champion Level 1

      Building on sanj's reply, depending on how you need to access the property there may be a few considerations you need to make.

       

      • If you need a property available across all test steps in a test case, store it at that test case level.
        • def testCaseProperty = testRunner.testCase.setPropertyValue("myTest", "blah")
        • (as provided by sanj)
      • If you need a property available across all test cases in a test suite, store it at the test suite level.
        • def testSuiteProperty = testRunner.testCase.testSuite.setPropertyValue("myTest", "blah")
      • If you need a property available across all test suites in a project, store it at the project level.
        • def projectProperty = testRunner.testCase.testSuite.project.setPropertyValue("myTest", "blah")
  • nmrao's avatar
    nmrao
    Champion Level 3
    It appears that the same question happened to be answered in stackoverflow:

    https://stackoverflow.com/questions/45840933/how-to-create-a-property-using-groovy-script

    Here is the appeal to the author. Please be patient while posting the questions with sample reproducible data, context and clear details so that external people can understand what exact the issue being faced. The time spent explain this not only helps you, but also to the people who willing to help others. Better the question, better the answer.

    Not sure where you searched online for the same, please refer below link which has more frequently used code snippets and I believe that is helpful to get started.

    https://www.soapui.org/scripting-properties/tips-tricks.html

    Thank you for the understanding and your cooperation.
    • sanj's avatar
      sanj
      Super Contributor

      It's the person's first post I would cut him some slack and just give the answer