Groovy Assistance - Change readlines from network to readlines from a property?
Hi,
I've been helped a lot by Rao, msiadak and others so far which got me to the point with the following groovyscript
def lines = new File('D:\\Donor Marketing\\SoapUI\\nongroovyscriptfile\\New Text Document.dat').readLines() lines.eachWithIndex { line, index -> if (index) { def data = line.tokenize('|'); log.info data[0]; context.testCase.testSteps["Properties"].setPropertyValue("CustRefID", data[0]); } }
Now the above reads a file on my local drive, parses the file and logs the CustRefID attribute value and passes the CustRefID value to a Properties test step.
Which is almost exactly what I need. HOWEVER - because I'm already sourcing the testdata using a Datasource (Directory) type test step at the start, I need to change this script so that rather than the following line
def lines = new File('D:\\Donor Marketing\\SoapUI\\nongroovyscriptfile\\New Text Document.dat').readLines()
I need to change the script so it parses the 'fileContents' property which is defined in my Datasource(directory) type.
I thought (Ive been doing some reading) that if I changed the line above to the following:
def lines = thisTestCase.getTestStepByName("Datasource - directory").getPropertyValue("fileContents").toString()
where the Datasource step = 'Datasource - directory' and the property defined in the datasource is 'fileContents' this would work - i.e. so the whole script reads as follows:
def lines = thisTestCase.getTestStepByName("Datasource - directory").getPropertyValue("fileContents").toString() lines.eachWithIndex { line, index -> if (index) { def data = line.tokenize('|'); log.info data[0]; context.testCase.testSteps["Properties"].setPropertyValue("CustRefID", data[0]); } }
however - I'm getting 'no such property' response when I run the script.
Can anyone advise please?
Again - many thanks to all for any assistance you can provide!
richie