使用多个Coded UI Test Map时控件无法定位的技术求助
Hey there! I’ve run into this exact problem before when splitting Coded UI tests across multiple UIMaps to support parallel work—let’s break down the most likely causes and fixes for your issue:
1. Your second UIMap isn’t tied to the correct application context
When you record a single UIMap, it automatically binds to the active application/browser window at the time. But when you use a second UIMap (especially one recorded separately), it might be searching for controls in a different context or even a non-existent window instance.
Fix:
Explicitly link your second UIMap’s controls to the main application window from your first UIMap. For example:
// Assume your first map is UIMapMain, second is UIMapSecondary var mainAppWindow = UIMapMain.UIMyApplicationWindow; // Set the main window as the parent context for your target control UIMapSecondary.UITargetControl.SearchProperties.Add("Parent", mainAppWindow);
Alternatively, when initializing your second map, force it to search within the active window’s title:
var secondaryMap = new UIMapSecondary(); secondaryMap.UITargetWindow.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch); secondaryMap.UITargetWindow.WindowTitles.Add(mainAppWindow.WindowTitle);
2. The second UIMap has unreliable control search properties
Coded UI picks search properties based on what’s available during recording. If you recorded the second UIMap when the control had a dynamic Name or temporary ControlId, those properties won’t work when you run the test alongside the first map.
Fix:
Open your second UIMap’s .uitest file, navigate to the problematic control, and update its Search Properties to use stable, unique identifiers like AutomationId (if your app supports it) or a combination of parent control properties + static attributes. Avoid relying on dynamic values that change between test runs.
3. Parallel execution is causing context isolation issues
If you’re setting up parallel tests, sharing static UIMap instances across threads will break control finding—each test thread needs its own isolated UIMap and application instance.
Fix:
Never use static UIMap instances. Instead, create new instances of each UIMap inside your test method to ensure thread isolation:
[TestMethod] public void ParallelTestScenario() { // Create fresh map instances for this test thread var mainMap = new UIMapMain(); var secondaryMap = new UIMapSecondary(); // Launch the app via the main map first mainMap.LaunchMyApplication(); // Ensure the secondary map targets this test's app instance secondaryMap.UITargetControl.Find(); }
Also, make sure each parallel test launches its own independent application/browser window to avoid cross-instance interference.
4. You’re not waiting for the control to load properly
Single UIMap recordings often include implicit waits, but when combining maps, you might be trying to access the control before it’s fully rendered or available.
Fix:
Add explicit waits before interacting with the control from your second UIMap:
var targetControl = UIMapSecondary.UITargetControl; // Wait for the control to be ready var waitForReady = new WaitForControlReady(targetControl); waitForReady.Wait(); // Or wait for it to become visible var waitForVisible = new WaitForControlVisible(targetControl); waitForVisible.Wait(); // Now interact with the control Mouse.Click(targetControl);
Give these steps a try—chances are one of them will resolve your control-finding issue!
内容的提问来源于stack exchange,提问作者Ali Alnader

