'Asserts that two HTML snippets are semantically the same.
Whitespace in most cases is ignored, and attribute ordering is not
significant. The passed-in arguments must be valid HTML.'

def assertHTMLEqual(self, html1, html2, msg=None):

    dom1 = assert_and_parse_html(self, html1, msg, u'First    argument    is    not    valid    HTML:')
    dom2 = assert_and_parse_html(self, html2, msg, u'Second    argument    is    not    valid    HTML:')
    if (dom1 != dom2):
        standardMsg = (u'%s    !=    %s' % (safe_repr(dom1, True), safe_repr(dom2, True)))
        diff = (u'\n' + u'\n'.join(difflib.ndiff(six.text_type(dom1).splitlines(), six.text_type(dom2).splitlines())))
        standardMsg = self._truncateMessage(standardMsg, diff)
        self.fail(self._formatMessage(msg, standardMsg))
