At first I wrote a lot of assertions of the style
If I press button A then assert number of visible rows = x, assert checkboxes checked are such assert title = bar .... [20 more]
and so on.
Then I switched to checksumming the HTML using MD5:
If I press button A then assert md5(html) = 8548bccac94e35d9836f1fec0da8115c.
And it made my life a whole lot easier...
But is this a bad practice in any way?
- I know a HTML file a.htm is working correctly, I copy it as
a_test.htm as a testcase I make all checksums using selenium in
dictionary.txt ('show_all' : ' 8548bccac94e35d9836f1fec0da8115c, 'hide_all' :3fdec30c2731d22e2516b1cd1261a1e1, 'filter_by_id_click' : 3fdec30c2731d22e2516b1cd1261a1e1) and so on..
- The use cases are done in selenium
- Further development that doesn't brake expected html output is safe, when assertion fails I diff the htmls...
UPDATE : Note that taking this approach can check dynamic behaviour, because of the fact that the md5 strings are build browserspecific from html in memory. The html is extracted from a selenium webelement that in its turn is taken from the current webdriver state.
I am not changing the way selenium handles things, just comparing the underlaying html.
To get dynamic content, I pass the loaded webdriver to a helper method that extracts the outerHTML of a given xpath expression (python)
def get_outerHTML_by_xpath(p_driver, p_xpath_expression): webelement = p_driver.find_element_by_xpath(p_xpath_expression) outerHTML= p_driver.execute_script("return arguments.outerHTML" , webelement) return outerHTML