0

New to groovy and seeking some help. I have a requirement where I need to compare XML files with similar names from two folders and I have to compare certain tags alone. Can anyone help me with this,

Ex : folder1 has xmls with name abc.xml, xyz.xml.
folder2 has xmls with name abc.xml, xyz.xml.

I need to check if folder1 and folder2 has file with similar name, if yes then go ahead and compare the XML's and print the difference (using groovy scripting in SOAPUI)**

Please see: Working on SOAP UI free version.

Was able to fetch the xml filenames from folder1 and folder 2 so far

def fileList1 = [] 
File folder1 = new File("Path of basefiles")

folder1.eachFileRecurse FileType.FILES, { f -> 
    if (f.isFile() && f.name.endsWith('.xml')) { 
        def filename1 = f.name[0..-1] 
        fileList1.add(filename1) 
        log.info filename1 
    } 
} 
if (fileList1.size() < 1) { 
    testRunner.fail("No request files") 
}

def fileList2 = [] 
File folder2 = new File("Path of response files")

folder2.eachFileRecurse FileType.FILES, { f -> 
    if (f.isFile() && f.name.endsWith('.xml')) { 
        def filename2 = f.name[0..-1] 
        fileList2.add(filename2) 
        log.info filename2 
    } 
} 
if (fileList2.size() < 1) { 
    testRunner.fail("No request files") 
}

if(fileList1==fileList2) 
    log.info true 
else 
    log.info false

Now, I want to ensure if there is any xml file with similar name in folder 1 and folder 2, I should compare those two xml's and print the difference.

Rao
  • 20,781
  • 11
  • 57
  • 77
  • 1
    How far did you get? As it stands, this question is quite broad as you're asking for code to take directory listings, parsing Xml (XmlSlurper?) and then comparing with other Xml based on some undefined criteria... – tim_yates Jan 26 '18 at 14:35
  • I was able to fetch the filenames from both the files so far – Apoorva Odugoudar Jan 26 '18 at 15:15
  • Maybe add your code to the question? Might help people help you with the part you're struggling with – tim_yates Jan 26 '18 at 15:16
  • Can you check this thread - https://stackoverflow.com/questions/48216562/compare-two-xmls-using-xmlunit-bypassing-the-order-of-elements – Rao Jan 31 '18 at 06:48

0 Answers0