Forum Discussion

URN123's avatar
URN123
Occasional Contributor
10 years ago

How to set "File Path" in DataSource test step using groovy

How to set "File Path" in DataSource test step using groovy?

I have multiple datasources in my test case and I want to set the path's inside each of the test cases using a groovy script. How can I do that?

Thanks in Advance.

5 Replies

  • URN123's avatar
    URN123
    Occasional Contributor
    Thanks "nmrao".

    Can you also provide me the groovy statement to be used to set the file path inside the datasource test step?
  • nmrao's avatar
    nmrao
    Champion Level 3
    You saw how to get a value of property, opposite of it to set. Use setPropertyValue(key, value)
    • juliandiazdepoo's avatar
      juliandiazdepoo
      Regular Visitor

      Rao, thanks for your explanation! Nevertheless, I did not figure out a way to put the file in the datasource-File. Can you pls support?

       

      Thanks in advance,

      Julian

      • Asish's avatar
        Asish
        Regular Visitor

        Try this - 

         

        def dataSourceStep = testRunner.testCase.getTestStepByName("DataSource");

        dataSourceStep.getDataSource().setFileName("FilePath");

         

        Cheers,

        Ashish

  • nmrao's avatar
    nmrao
    Champion Level 3
    You may add a property at test case level for the same(say FILE_NAME) and access its value in groovy script of the test case.

    def fileName = testRunner.testCase.getPropertyValue('FILE_NAME')


    In case if it requires multiple files, define property(FILE_NAMES) value as comma separated(/path/to/file1,/path/to/file2) then split it using comma in the groovy script so that you get an arry and then loop thru it.

    def fileNames = testRunner.testCase.getPropertyValue('FILE_NAMES')
    def fileNamesArray = fileNames.split(',')
    fileNamesArray.each { fileName ->
    //do the stuff
    }