Post

1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

By Google Testing Bloggers
by Ruslan Khamitov This article was adapted from a Google Testing on the Toilet (TotT) episode. You can download a printer-friendly version of this TotT episode and post it in your office.Adding ID attributes to elements can make it much easier to write tests that interact with the DOM (e.g., WebDriver tests). Consider the following DOM with two buttons that differ only by inner text:

Save button
Edit button

Save
Edit

How would you tell WebDriver to interact with the “Save” button in this case? You have several options. One option is to interact with the button using a CSS selector:div.jfk-button
However, this approach is not sufficient to identify a particular button, and there is no mechanism to filter by text in CSS. Another option would be to write an XPath, which is generally fragile and discouraged://div[@class=’jfk-button’ and text()=’Save’]
Your best option is to add unique hierarchical IDs where each widget is passed a base ID that it prepends to the ID of each of its children. The IDs for each button will be:contact-form.save-buttoncontact-form.edit-button
In GWT you can accomplish this by overriding onEnsureDebugId()on your widgets. Doing so allows you to create custom logic for applying debug IDs to the sub-elements that make up a custom widget:@Override protected void onEnsureDebugId(String baseId) {super.onEnsureDebugId(baseId); saveButton.ensureDebugId(baseId + “.save-button”); editButton.ensureDebugId(baseId + “.edit-button”);}
Consider another example. Let’s set IDs for repeated UI elements in Angular using ng-repeat. Setting an index can help differentiate between repeated instances of each element:
In GWT you can do this with ensureDebugId(). Let’s set an ID for each of the table cells:@UiField FlexTable table;UIObject.ensureDebugId(table.getCellFormatter().getElement(rowIndex, columnIndex),baseID + colIndex + “-” + rowIndex);
Take-away: Debug IDs are easy to set and make a huge difference for testing. Please add them early.

Source: http://feedproxy.google.com/~r/blogspot/RLXA/~3/XrZj1T_nMns/testing-on-toilet-web-testing-made.html

Category: Ruslan Khamitov, TotT

Você também pode querer ler

Comments are off for this post.