Freigeben über


UI automation breaking due to window title changing each time?

When testing UI applications, specially web apps, we frequently encounter the problem of window title changing with the state of the app or operations done on the app. For instance, when checking web mail, the title of the page could read “Inbox(35) - Microsoft Internet Explorer” where 35 really represents the number of unread email in your inbox. Now, when I open it at any other time, it might read “Inbox(36) - Microsoft Internet Explorer” based on unread mail. For GUI testers, this poses a problem since object identification works usually on the basis of window title and the title changing each time I run the test causes object identification to fail. :(

To solve this problem, the API of VSTS 2010 has a “Smart Match” feature built into it. Thej Kumar is our smart young developer that works on the record and play engine of Team Test and today, he will explain how smart match works. So, here you go:

Baseline assumptions:

    • The assumption is that the title of the window is of the form <Title> - <Application Name> or <Application Name> - <Title>.
    • The assumption is that the last hyphen separates the title from the application name.

How does the heuristic work:

    • If the application name matches completely, we ignore it in the calculation of score for a window. In the above example, “Microsoft Internet Explorer” is a complete match. Hence the scores are calculated only for Inbox(35) and Inbox(36).
    • Whichever window has the longest common string will have a higher score. Example: “Inbox, 45 unread” and “Inbox, 46 unread” will be a 50% match because the longest common string is 8 (Inbox, 4) out of the total length of 16. On the other hand, “Inbox, unread(45)” and “Inbox, unread(46)” will be excellent matches because the longest common string is 15 out of 17.

Special case for MDI windows:

    • Title changes based on whether or not the MDI window is maximized or restored. Eg: if the title of the main window is A and the title of MDI window is B, if B is maximized, the title of A changes to A – [B]. To handle these cases, we give a high score to windows whose one half matches and the other half of only one of the windows is empty.
    • If two or more windows get a good score, the window on the top is picked up.

Good things to do regarding titles to ensure smart match picks works correctly:

    • Ensure that the last hyphen separates the title from the application name and in general, avoid too many hyphens in the title.
    • Ensure that part of the title that changes is present either in the beginning or in the end.
    • Ensure that the window which you want to be picked up is present on top of the other windows.

Sometimes on a rare occasion, smart match does end up being oversmart ;-) and gives false positives, but those scenarios can be worked around. Tell us what you think of smart match!