Hi,
I'm sorry - I might not be understanding all of the question correctly - so I'm going to just describe and hope I answer your question.
Using the datasource (Directory) option (when you have multiple files in the directory) and the previous approach discussed will just (starting from the first file) grab the file and post the filecontents via the fileContents property created on the directory datasource, and move onto the next file (as long as there are multiple files in the directory and you have a datasourceloop step).....there's no way I know of to grab a specific file in the directory
Including multiple files in the datasource allows you to use the datasourceloop step. If you have only a single file in the directory - the test will run once and using this approach you know which file you have picked up (because there's only 1 in the directory).
Using the datasourceloop step only works if the assertions on the REST/SOAP test steps in your test case are identical for each of the test data files you have in your directory
I sometimes have multiple files in my datasource (directory type) and then I include a datasourceloop step at the end to move onto the next file in the directory to repeat until all files are processed.
Othertimes I have a single file in my datasource (directory type) and then I don't include a datasourceloop step because there's no point.
From your post you state "- Here is my scenario, 5 Post requests & for each I'm getting JSON data from directory via data source & 5 test cases are created, so want to use those JSON data in respective 5 Post requests. Currently I'm validating by adding datasource in each test case to get JSON & calling same JSON via Get Data option at request."
You state you have 5 ,json test data files, 5 posts, and 5 test cases. If you have 1 testcase rather than 5 - you would have multiple files in your datasource and you would include the datasourceloop step in the testcase. If you are stating you have 5 test cases, you wouldn't include multiple files in the datasource.
I'm struggling a bit here to see the problem - please see the possibly testsuite hierarchies you have a choice on below:
TestSuite1
TestCase1
Datasource (directory) - 1 file (fileContents property)
POST Request (sourcing ${Datasource#fileContents})
TestCase2
Datasource (directory) - 1 file (fileContents property)
POST Request (sourcing ${Datasource#fileContents})
TestCase3
Datasource (directory) - 1 file (fileContents property)
POST Request (sourcing ${Datasource#fileContents})
TestCase4
Datasource (directory) - 1 file (fileContents property)
POST Request (sourcing ${Datasource#fileContents})
TestCase5
Datasource (directory) - 1 file (fileContents property)
POST Request (sourcing ${Datasource#fileContents})
OR
TestSuite1
TestCase1
Datasource (directory) - 5 files (fileContents property)
POST Request (sourcing ${Datasource#fileContents})
DatasourceLoop
As I state above - the option of having multiple files in your datasource means you can loop and means you only have 1 test case. This is handy - but will only work if the assertions you create on your POST request are valid for all 5 runs for your tests.
I don't know whether I've helped at all or just rambled on.
Does that help? Or if not - can you try and be a little more descriptive in your question?
Cheers,
richie