One of the most frequent questions regarding Coded UI Tests goes like this – “I have a test running very well on my machine. But when I run it on another machine, it becomes very slow.”
When our team investigates, in most cases (not all), this is due to changes in the test environment. (primarily in Window Name). i.e When running on the local box, the test would have been recorded on the Application Window with name ”Application v184.108.40.206”. When the test is run on a different box, the Application Window title has changed subtly. Name has now become “Application v220.127.116.11”.
In this case, the UI Test Framework attempts to find the application window with name “Application v18.104.22.168” and fails in its first attempt. It then waits for a timeout (default 2mins) and attempts again with a Smart match algorithm. Using Smart Match, it will correctly identify the new title “Application v22.214.171.124” and proceed to run the rest of the Coded UI Test successfully. The information that a smart match has been applied is available in the trace logs. (not in the Test Results).
- How do you confirm that your Coded UI Tests are running slower because of Smart Match timeout?
You will find a warning in the debug trace similar to:
W, 8748, 6, 2011/03/01, 08:28:28.195, 155961250575, QTAgent32.exe, Playback – [WARNING] Internal warning: Window with Class "WindowsForms10.Window" and Title "Application v126.96.36.199" was not found, so similar window with Class "WindowsForms10.Window.8.app.0.2bf8098_r13_ad1" and Title "Application v188.8.131.52" was accepted.
- How do you fix the Coded UI Test so that tests complete quicker under such scenarios?
You can modify the Window search to handle the dynamic name. You do this by adding a UIMap constructor in the file UIMap.cs and override the Window name search.
this.UIApplicationv1013Window.SearchProperties.Add(WinWindow.PropertyNames.Name, "Application v", PropertyExpressionOperator.Contains);
Here I have modified my Window Name search to just “Application v” and I am ignoring the dynamic version component of the title.