Comment 4 for bug 844450

Revision history for this message
Leo Arias (elopio) wrote :

In your first example, you are using the name as an identifier. It's not bad and it works, but it can be better. Instead of telling the website developers: "You should make sure that the combination of tag, text, class and name uniquely identifies your elements", you could tell them: "Set a unique id for the elements that should be tested".

The id is the only element that's required to be unique by the specification [1]. So, having two elements with the same name is not a bug, and there are lots of cases where having the same text and class is required. In your second example, you add the text, but that doesn't always work, and you can see the Services page example I mentioned. This page has no visible UI issues, it makes perfect sense to have the same text on both buttons. The bug there is not the lack of a unique name/text/class/... combination, it's the lack of an id.

We always have a workaround making xpath expressions as complex as required, so we might think of this as a low priority issue; but as it has the chance to break the tests so easily, I consider this as a major problem. Expanding on what I mentioned before, button_click(get_element(name='continue')) will work until somebody adds a second button named continue. The fault will not be of the developer, it will be the tester's fault for relying on something that doesn't uniquely identify the element. get_element(tag='button', text='Yes, remove') will work until somebody decides that the text should be shortened to 'Yes'. The fault here will be of the tester for relying on something that's likely to change.

Another important point is that elements like span [2] don't have a name attribute. For consistency and ease, all elements must be uniquely identified by their id. It makes a lot of sense to me :)

Finally, for readability and maintainability while using sst, this is much better: button_click('continue')

This, of course, is just my opinion. I think that source code must be written with testability in mind, and that by trying to make the tests for your code as easy as possible, your code will be of a higher quality. As a result, your tests will also be of a higher quality. But we can make some compromises here, like setting the importance of this bugs to medium :D

pura vida.

[1] http://www.w3schools.com/tags/att_standard_id.asp
[2] http://www.w3schools.com/TAGS/tag_span.asp