Merging multiple Squish reports

Last edited on

The following Python script can be used to combine multiple Squish reports into a single file ( merge_squish_reports.py ):

# -*- coding: utf8 -*-

from xml.dom.minidom import parse
import xml.dom.minidom
import sys

if len(sys.argv)<3:
    print "ERROR: Please specify the paths of at least two XML files to be merged."
    print
    print 'USAGE: "%s" xml_file1 xml_file2 [xml_file...n)' % (sys.argv[1])
else:
        xml_file1 = sys.argv[1]
        xml1 = xml.dom.minidom.parse(xml_file1.encode("utf-8"))
        for file_name in sys.argv[2:]:
            xml2 = xml.dom.minidom.parse(file_name.encode("utf-8"))
            x = xml2.importNode(xml2.getElementsByTagName("test")[0], True)
            xml1.getElementsByTagName("SquishReport")[0].appendChild(x)
        print xml1.toxml("utf-8")
merge_squish_reports.py

Example usage:

python merge_squish_reports.xml report1.xml report2.xml >combined_report.xml
In cmd.exe or a shell