Search code examples
wpfmicrosoft-test-managervisual-studio-test-runner

Test Runner can't find controls during replay


I just started with Microsoft Test Manager 2015 and build two test cases.

First one involves clicking on a tray icon and selecting an entry from there - which works fine.

Second case is a bit more complex, I wanted to fill out a form in a WPF window and click some buttons.

The recording went without a problem but the replay doesn't work at all. It should start with selecting a TabItem, select another TabItem that is inside the previous selected TabItem and then fill out the text fields and press a button and confirm two message dialogues.

Problem is, TestRunner isn't able to find any of my controls. Even if I select the correct TabItem and just try and execute one of the 'enter someText here' steps, it takes some time and then throws an exception in my face which, roughly translated, says that the replay of the selected step couldn't be completed because it couldn't find a control that matched the search properties(?). Then follows a List:

TechnologyName: 'UIA'
FrameworkId: 'WPF'
ControlType: 'TabPage'
AutomationId: 'sometabname'

all of that is correct. If I try to execute a different test step it says basically the same thing but instead of 'ControlType: TabPage' it says 'ControlType: Edit'.

I'm not sure how to proceed from here. I did some searching but all I could find were questions about UIAutomation configuration/set-up but as far as I can tell I can't influence/control that directly in MTM.

edit

After simplifying the test 'case' (just click the abort button that is directly placed in the Window/first grid) and editing the mtm.exe.config file and enabling tracing/logging I got this out of the respective logfile:

mtm.exe, Playback - [WARNING] Internal warning: Target element "[UIA]FrameworkId='WPF' && ControlType='Button' && AutomationId='closeWithoutSave'" was not found, so all intermediate elements were ignored. An incorrect element that matches target element Id can be found as the result. Verify that all intermediate elements in QueryId have valid and unique Ids
mtm.exe, Playback - [WARNING] Internal warning: Search failure: [UIA]FrameworkId='WPF' && ControlType='Button' && AutomationId='closeWithoutSave' | Performed (4) searches, UI element not found
mtm.exe, Playback - {1} [FAILED] Function ElementFetcher::FindScreenElement failed to locate UI element (;[UIA]FrameworkId='WPF' && ControlType='Button' && AutomationId='closeWithoutSave') (Das angegebene Objekt wurde nicht gefunden.) 

What is weird here is that I even set the Automation.AutomationID on that button and it still failed. Also I'm not sure if that is right but the search doesn't seem to include the name/automationID of the Window that has that button. Since I've, at that point, two windows open in the application I could imagine that being the problem.


Solution

  • I inspected the UI test that was generated by MTM by loading it into a Coded UI Test Project. I opened the UI Control Map and saw what was wrong:

    The TabControl/TabPage navigation was grouped in the same Window as the ContextMenu of the TrayIcon.

    The reason for that was, that instead of using the Name property of a WPF Window, MTM/Coded UI Tests use the Title property as the identifier of a Window (wtf?).

    The Solution:

    Setting the Title property of my WPF configuration window to Configuration and redoing the affected test steps solved the problem.

    Hint for people with a similiar problem: It may also help to increase the MaxLevelsForItemContainer value in the mtm.exe.config file that is located in Common7\IDE of your Visual Studio installation folder.