t.me/atinfo_chat Telegram группа по автоматизации тестирования

Coded UI Test is not able to find control in runtime

(monkerwack) #1

Hi, i'm testing .Net application. I recorded a coded UI test that starts application, opens one window, pushes the button that opens another window, fills some fields and closes application. It's quite simple workaround. When i run the test i'm getting an error:


Test method CodedUITest1.TEMP_METHOD threw exception: 
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: The playback failed to find the control with the given search properties. Additional Details: 
TechnologyName:  'MSAA'
ControlType:  'Edit'
Name:  'Имя:'
 ---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.

But then i opened UI map designer and tried to locate all controls. All controls are locating well with blue color around them. It seems like problem occurs only during playback.

Anyone has idea about it?

(levaal) #2



try to record a method working with this control and launch it. If it will work then the problem is in your code.


It sometimes happens when you have an element structure like A -> B -> C -> D -> E  , and you want to work with E element, but you've defined only A and E elements (or even only E). Try to define  also parent control for E (that is D).


Also, you may enter here the piece of code that is causing the problem so we'll be able to see if there is something wrong.




(monkerwack) #3


I've tried to record method that works only with this control and it works fine.
But unfortunately it doesn't work in situation where  (Window1 - >press button - >Window2 ->Locate control failed). When Window2 opens i can see that it's being recorded by "Currently recording" in the top right corner of the window.  And again, it confuses me because i can surely locate this control and all his parent controls within the UI map after the test has failed.
Problem occurs in line:
uI_TextBoxNameEdit.Text = this.TEMP_METHODParams.UI_TextBoxNameEditText;
Control settings:
public WinEdit UI_TextBoxNameEdit
                if ((this.mUI_TextBoxNameEdit == null))
                    this.mUI_TextBoxNameEdit = new WinEdit(this);
                    #region Search Criteria
                    this.mUI_TextBoxNameEdit.SearchProperties[WinEdit.PropertyNames.Name] = "Имя:";
                    this.mUI_TextBoxNameEdit.WindowTitles.Add("Без имени");
                return this.mUI_TextBoxNameEdit;

(levaal) #4

Pay attention to displayed structure in Coded UI Test Builder (when inspecting the element). Is this edit wrapped into a window with relatively the same borders?


if yes, try defining the element as per following:


public WinEdit UI_TextBoxNameEdit
                if ((this.mUI_TextBoxNameEdit == null))
                    WinWindow parentWindow = new WinEdit(this);
                    parentWindow .SearchProperties[WinEdit.PropertyNames.Name] = "Имя:";
                    parentWindow .SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
                    parentWindow .SearchConfigurations.Remove(SearchConfiguration.VisibleOnly);
                    this.mUI_TextBoxNameEdit = new WinEdit(parentWindow);
                return this.mUI_TextBoxNameEdit;

(Виталий) #5

How did you run your test, local or remotely?

There can be some issues with remote execution.

(chudeska) #6

Do you exclude the possibility  that your test tryes to work with the window which is not upoaded/opened yet?

(monkerwack) #7

After almost 8 wasted working hours of monkey-googling and forum-posting i suddenly stumbled upon solution. 

In a rage of blindly changing all the search parameters, accidentally i changed Search cofigurations for Window2 (where my control is located) from "Visible only" to "Always search" and it worked!
Why the hell window that is on the top of all windows is invisible for the program only devil knows. Maybe CodedUI Test builder has problems with multiple windows opened one from another, maybe it's only my project-specific troubles, anyway, problem is solved, and i'm going to have my beer.
Thanks to all for your help.
Solution: change parent window search parameters to "Always search"