Forum Discussion
This issue has interested me and because I was looking at the Groovy DataSource for another issue I thought I'd turn this into a full example, it may possibly help you or perhaps someone else. I've attached a full stand-alone sample project, where you will just need to go to the DataSource step and update the path to your file (assuming you have already added the Apache commons CSV library jar file to you bin/ext directory).
The things I like about this solution is:
- Let the CSV library deal with parsing out your data (why reinvent the wheel?)
- It minimises the Groovy, which is all in one place.
- You can now access your pipe delimitted data in the standard Ready API way as it is now just properties of the DataSource test step within a DataSource Loop.
Below is a screen shot from the attached project of the Groovy DataSource and you can see that your data has been parsed at the bottom:
Well, here are my comments :
1. The code presented by me is much simpler, readable and condensed than other samples presented above.
2. No custom library is used.
3. No reinvention here, just groovy, I believe (as only separator changed and it is applicable even if other libraries are used) at least for this case requested by original poster.
If at all custom library needs to be used, below is very simplified and groovified:
https://github.com/xlson/groovycsv