I am new at selenium testing and am writing a bunch of tests for a webpage that relies heavily on javascript user interaction.
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?
example
- 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
(driver.findbuttonShowAll.click(), assert(md5(html)==dict['show_all])
- 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.