Ask a Question

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

URN123
Occasional Contributor

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 5
nmrao
Community Hero

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
}


Regards,
Rao.
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
Community Hero

You saw how to get a value of property, opposite of it to set. Use setPropertyValue(key, value)


Regards,
Rao.

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

Try this - 

 

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

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

 

Cheers,

Ashish

cancel
Showing results for 
Search instead for 
Did you mean: