Cause :
The Coded UI Test is running in Single Thread Apartment (STA) mode of COM. In this mode, all the playback calls should happen from the TestMethod thread only and UITestControl should not be shared across TestMethods.
Situation:
Create a test project which contain several class - Unit Test Class and each class contain several test method.
In each test method, we define UIMaps related to different application and call UI to finish work flow.
If we want to run these test method, we have to do playback.initial for this class is not "CodedUI" class.
So, user have to initial placyback by itself.
So, in each test method, we should have these codes:
private static Boolean initializedByMe = false;
if (!Playback.IsInitialized)
{
Playback.Initialize();
Playback.PlaybackSettings.MatchExactHierarchy = true;
Playback.PlaybackSettings.SearchInMinimizedWindows = false;
Playback.PlaybackSettings.ShouldSearchFailFast = true;
Playback.PlaybackSettings.SkipSetPropertyVerification = false;
Playback.PlaybackSettings.SearchInMinimizedWindows = false;
initializedByMe = true;
}
After i add these and run again, then i match the problem that be mentioned at first of this article.
Do searching to fix this problem and found this article:
Solution:
After test method is finished, should clean playback. Then the later test method can reload UIMap and find exactly one on testing