AAB45Old
17 hours agoNew Member
Reuse adapted xml file and send in REST
Hi SmartBear,
Long time ago that I was here (under a different name :-) ). Glad to be back though ;-)
So, my question:
We want to send a file as Query, cached, multipart/form-data.
After sending we need to adapt, e.g. the vinnumber, save the file and send again with REST request.
For the moment I have this:
import groovy.xml.XmlParser
import groovy.xml.XmlUtil
// 1 Generate VIN
def chars = "ABCDEFGHJKLMNPRSTUVWXYZ0123456789"
def random = new Random()
def generatedVin = (1..17).collect { chars[random.nextInt(chars.length())] }.join()
log.info "Generated VIN: " + generatedVin
// 2 Get file path from test case level -->wll fetch it from folder project
def filePath = context.expand('${#TestCase#file}')
def file2 = new File(filePath)
log.info "File path: " + filePath
// 3 Parse XML
def xml = new XmlParser().parse(file)
// 4 Update VIN
xml.Body.VehicleTransportOrder.Line.Vehicle.VehicleID[0].value.generatedVin
// 5 Write updated XML
def writer = new FileWriter(file2)
XmlUtil.serialize(xml, writer)
writer.close()
log.info "VIN replaced successfully"The original file came with the composite testproject as everybody needs to be able to reach that file. We don't know if this would be better put in a folder because we will have different files from different clients. But this is what we came up to.
The file is read correctly, the vinnumber = generated, but the new number can't be put in that attached file anymore.
Anybody an idea on what should be the best steps now?
Thanks in advance, AAB