Forum Discussion
Not sure what exactly the further.
Is that you need to ignore the last line (Rows=1) which is not actual data?
Then you change it from:
if (index) {
to:
if (index && (lines.size() != index+1)) {
Hey Rao,
I'm sorry - I'm not being clear enough in my descriptions.
I already have a datasource with a filecontents property (which holds the whole file contents). What I need is ANOTHER test step (I'm guessing using groovy) to pick out the CustRefID attribute value from the file, as I have a GET step that uses the CustRefID in the GET request to confirm the POST was successful.
I am expecting my TestCase to look like the following
DataSource - DirectoryType (fileContents property)
GroovyStep <-- to extract the CustRefID value from the fileContents property POST /path/synchronous-upload <-- this POST publishes the fileContents property GET /path/contact?CustRefID=${#TestCase#CustRefID}
I can't rely on the POST response providing the CustRefID, to extract to pass onto the GET request, so I need to extract it (I think) from the fileContents property
The file contents are as follows:
CustRefID|title|firstname|lastname|addressline1|addressline2|addressline3|postcode ID0000001|MR|RICH|JONES|5 WHATEVER WAY|HODGE HILL|BIRMINGHAM|B36 9LB Rows=1
Your original script was as follows:
def lines = new File('D:\\Donor Marketing\\SoapUI\\nongroovyscriptfile\\New Text Document.dat').readLines()
lines.eachWithIndex { line, index ->
if (index) {
def data = line.split('|')*.trim()
log.info data[0]
}
}
When I ran your original script - an 'Information' dialogue appears with the whole file contents displayed, and the info in the log output reports the following:
Tue May 23 10:46:56 BST 2017:INFO:I Tue May 23 10:46:56 BST 2017:INFO:R
As you can see - it appears the script is logging the first character of every line after the header row.
I am hoping I can change your script to capture the whole value of 'ID000001' so I can pass it to the GET request later in my test case.
In summary - I'm hoping you can help editing your script so that it parses the fileContents property and captures the 'ID0000001'
I did edit your script to the following:
def lines = new File('D:\\Donor Marketing\\SoapUI\\nongroovyscriptfile\\New Text Document.dat').readLines()
lines.eachWithIndex { line, index ->
if (index) {
def data = line.split('|')*.trim()
log.info data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7] + data[8]
}
}and the logging was as follows:
Tue May 23 10:46:56 BST 2017:INFO:ID0000001 Tue May 23 10:46:56 BST 2017:INFO:Rows=1nullnullnull
I only need to capture the ID0000001 value - so that I can pass it to the GET Request.
I hope I've been clear - at this point, I need to edit the script to parse the fileContents property (rather than from the directory as the script currently is doing (because I'm going to use a Datasource of Directory type with lots of files to cycle through) and to ONLY capture the ID0000001 value.
Many, many thanks to all, and especially Rao,
richie