Santi tweeted a link to DOM Monster which I think I had seen before but for some reason decided to spend the hour to cobble up a Se script that will fetch the information it provides on a page.

I’m not sure I’d actually use this since most of the information it provides is likely a result of importing 3rd party JS libs into your code, but off the top of my head you could…

  • Run it against each page in the Page Object __init__
  • Fail scripts if there are any warnings
  • Filter known messages you don’t care about
  • Compare against known amounts of messages and alert a human if it has changed

Enjoy.

<pre lang="python">import CustomTestCase

from nose.plugins.attrib import attr
from nose.plugins.skip import SkipTest

class MonsterExample(CustomTestCase.CustomTestCase):
    @attr(tags=['monster'])
    def whos_da_monster(self):
        """
        Clever function for getting DOM Monster (http://mir.aculo.us/dom-monster/) information from a page.
        """
        # navigate to the page you want. this example uses page objects so just
        # ignore the 'how' we get the page
        p = self.login_as_reviewer()
        dashboard = p.goto_random_draft_project()
        try:
            p.se.set_timeout("1000")
            p.se.open("javascript:(function(){var%20script=document.createElement('script');script.src='http://mir.aculo.us/dom-monster/dommonster.js?'+Math.floor((+new%20Date)/(864e5));document.body.appendChild(script);})()")
        except Exception as e:
            if str(e).find("Timed out after") != -1:
                p.se.set_timeout("30000")
            else:
                raise
                
        if p.se.is_element_present("//div[text()='warn']"):
            warns = []
            for warn in range(0, int(p.se.get_xpath_count("//div[text()='warn']"))):
                warns.append(p.se.get_text("xpath=(//div[text()='warn'][1]/..)[%s]" % str(warn + 1)).split("\n")[1].strip())

        if p.se.is_element_present("//div[text()='tip']"):
            tips = []
            for tip in range(0, int(p.se.get_xpath_count("//div[text()='tip']"))):
                tips.append(p.se.get_text("xpath=(//div[text()='tip'][1]/..)[%s]" % str(tip + 1)).split("\n")[1].strip())

        # do stuff with the warnings
        self.assertEqual([], warns)