Forum Discussion

Apoorva6's avatar
Apoorva6
Frequent Contributor
9 years ago

How to transfer Groovy variable to another Groovy Step ?

Hi,

 

I have a Groovy testStep named Groovy_AC and have a variable named filename . Using Groovy_AC, filename will get a value each time it is run. I need to access this filename variable in another Groovy test step named Groovy_AH. Can I use property transfer step for this ? if so how ? There are many variables in Groovy_AC test step and how can I transfer filename alone ?

 

Apart from above, I need to transfer filename from Groovy_AC teststep to a JDBC step also, how can I acheive this ?

1 Reply

  • nmrao's avatar
    nmrao
    Champion Level 3

    Property transfer is not required.

     

    If possible define a custom property for file name at test case level, so it can be used in any test step of the test case.

     

    From Groovy Script:

     

    def filename = context.testCase.getPropertyValue('FILE_NAME')

     

    From other step, it can be accessed using property expansion such as ${#TestCase#FILE_NAME}

     

    If you want to explicitly set the file name in one groovy script, then use below command to set the value at test case level custom property

     

    context.testCase.setPropertyValue('FILE_NAME', '/absolute/path/of/file')

    And by now, you already know how to access the above value in any other steps of the same test case.