Extract Specific Value from nonXML datafile to provide JDBC request with query filter value
Hi,
This is very similar to a previous post I submitted and nmrao and Radford really helped me out, but now instead of XML, my testdata files are | delimited text files.
I need to parse a test data file (| delimited text file) and then scrape the content of the testdata file via groovyscript to hold the CustRefID value to then pass that value to the JDBC step to query the database after I've posted to the web service.
For my previous request (with XML) Radford and nmrao told me to use the following
import groovy.util.XmlSlurper
def xmlText = context.expand( '${DataSource#FileContents}' ) //where FileContents is the property set on my DataSource object)
def RecordInput = new XmlSlurper().parseText(xmlText)
log.info(VenueInput.VenueProfile.@VenueID) Now the above works great - but now I need to change this so it works with | delimited text files
The format of the file is as follows:
CustRefID|title|firstname|lastname|addressline1|addressline2|addressline3|postcode ID0000001|MR|RICH|JONES|5 WHATEVER WAY|HODGE HILL|BIRMINGHAM|B36 9LB ID0000002|MRS|ALISON|WHITEFORD|6 READY ROAD|WHITTAKER|FOUR OAKS|B74 4TH Rows=2
As you can see - there is a header (which lists the attributenames), there are 2 data rows and a footer that indicates the number of data rows.
I need to extract the first value in each data row - so for the example above I need to grab the values 'ID0000001' and 'ID0000002'
I'm sorry to have to ask such a basic question - but I'm struggling - I've found some groovy to read the contents of the file from the directory e.g.
String fileContents = new File('/path/to/file').getText('UTF-8')but I haven't found anything that allows me to source a specific value from a certain position in the file (e.g. first value in each data row) and also my coding is so bad I'd like to try and keep things as consistent with my other test cases as possible - e.g.
Thanks to anyone who can help!