Software Rants
Software Rants
How to write a website to enable automation
Wednesday, 22 July 2009
I’ve been working on a website for the past several months. One of the things that really bugs me is that the developer don’t want to add ID attributes to each of the elements of the website. This is in some respects fair enough because the easy way to do this is enable the ASP.NET ID attributes to be added to the items. This can double the size of the webpage because the lovely people at Microsoft weren’t thinking about that when they developed the feature. I hear a fix is coming for that...
So why would you want to add ID attributes to items in the first place?
Consider the follow. There is a paragraph in the page that contains a link which can change depending no how the page was accessed, by whom, etc... and you want to check if the link exists in the paragraph.
- The wrong way to do this is to check the whole page to see if each of the possible links exist. This is wrong because a number of negatives is not necessarily a positive.
-Another wrong way to do it is to look for a link the that paragraph. This is wrong because it means that you have to know the structure of the page which means that if the structure of the page changes but the content should still be the same the test will fail.
-The right way is to check that the link exists by checking if the element can be found with that ID. This enables you to check with out knowing anything about the document structure. Which means that the test will continue to work long after the page has been restructured.