0

I have this issue with some Win controls. There is a Date DropDowns that I want to access, however both start and end Date identical (todays date), so replay goes to first one -start Date- everytime, both for Start Date and End Date comboboxes.

My question is related to this old post and I see issue in this post still not fixed / answered CodedUI : PropertyNames.ControlName doesn't work

When I spy over comboboxes I see ControlNames are unique so I tried to use control names for the controls , through UIMap.uitest I added ControlName to SearchProperties collection and write the values however now it can not find.

 public WinControl UIItem17Ocak2019PerşemDropDown { get { if ((this.mUIItem17Ocak2019PerşemDropDown == null)) { this.mUIItem17Ocak2019PerşemDropDown = new WinControl(this); #region Search Criteria this.mUIItem17Ocak2019PerşemDropDown.SearchProperties[UITestControl.PropertyNames.ControlType] = "DropDown"; this.mUIItem17Ocak2019PerşemDropDown.SearchProperties[UITestControl.PropertyNames.Name] = "17 Ocak 2019 Perşembe"; this.mUIItem17Ocak2019PerşemDropDown.SearchProperties["ControlName"] = "bBasT"; this.mUIItem17Ocak2019PerşemDropDown.WindowTitles.Add("Filtre"); #endregion } return this.mUIItem17Ocak2019PerşemDropDown; } } 

here is exception I am getting

 Message: Test method CodedUITestProject2.KayitTablolari_HurdaListesi.HurdaListesiTabloKontrol 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: 'DropDown' Name: '17 Ocak 2019 Perşembe' ControlName: 'bBasT' ---System.Runtime.InteropServices.COMException: Bir COM bileşenine yapılan çağrıdan HRESULT E_FAIL hatası döndürüldü. 

Or is there a way for order of controls in the window? such as "not click first but click second combobox in the window."

4
  • 1
    Please try the following: 1. Try using only the search properties you really need to uniquely identify your controls. It will prevent your "query" from being to narrow, which could result in no controls found. 2. When multiple controls are found for given search properties, the first found control will be used. 3. Adding a parent argument to the Wincontrol instance will tell your test it should search for a child in the parent control. Referencing the wrong parent, I'm not sure you will find the control you are looking for. Try instantiating that WinControl without referencing a parent. Commented Jan 17, 2019 at 10:03
  • Hi PixelPlex I alread tried use ControlName soley but it did not work. The AUT I am testing has uniqu controlNames everywhere but I never seen ControlName works for a control yet. All controls are ujnder same control, I dont think parent control will work in this case. Can you give some code examples for my win control ? Commented Jan 17, 2019 at 13:17
  • I made a test winforms project with 2 comboboxes and filled it with a few dates. Seems to work fine when I record a test. Looking up the recorded method in code, I noticed the comboxboxes got added to the test as WinComboBox objects instead of WinControl. Searchproperty used is WinComboBox.PropertyNames.Name, nothing more. Commented Jan 17, 2019 at 15:41
  • Problem is not whether its wincontrol or WinComboBox. I have no problem with Name property, problem is with ControlName property. Anyway I found a solution and posted the answer. Commented Jan 18, 2019 at 5:43

2 Answers 2

1

I found a solution, as described in below page, controlName is not for individual controls but for windowed controls, such as WinWindow.

https://blogs.msdn.microsoft.com/vstsqualitytools/2010/01/15/understanding-the-window-search-and-windowed-properties/

Sign up to request clarification or add additional context in comments.

2 Comments

Interesting, I did not know about that yet. But didn't your UIMap sort this out in its generated code? I noticed in the generated code from the UIMap of a test project I had made, the UIMap uses the ControlName property for WinWindows, and the Name property for WinComboBox objects. I'll add a answer to your question to illustrate this.
Not every line generated. I manually added line with the ControlName but before I added it for wrong win control.
1

Following on Rasim Avci's anwser, below code illustrates generated code from a UIMap. The program under test was a windows Forms project containing a Form with a ComboBox on it.

[GeneratedCode("Coded UITest Builder", "15.0.26208.0")] public class UIForm1Window : WinWindow { public UIForm1Window() { #region Search Criteria this.SearchProperties[WinWindow.PropertyNames.Name] = "Form1"; this.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains)); this.WindowTitles.Add("Form1"); #endregion } #region Properties public UICbStartDateWindow UICbStartDateWindow { get { if ((this.mUICbStartDateWindow == null)) { this.mUICbStartDateWindow = new UICbStartDateWindow(this); } return this.mUICbStartDateWindow; } } public UICbEndDateWindow UICbEndDateWindow { get { if ((this.mUICbEndDateWindow == null)) { this.mUICbEndDateWindow = new UICbEndDateWindow(this); } return this.mUICbEndDateWindow; } } #endregion #region Fields private UICbStartDateWindow mUICbStartDateWindow; private UICbEndDateWindow mUICbEndDateWindow; #endregion } [GeneratedCode("Coded UITest Builder", "15.0.26208.0")] public class UICbStartDateWindow : WinWindow { public UICbStartDateWindow(UITestControl searchLimitContainer) : base(searchLimitContainer) { #region Search Criteria this.SearchProperties[WinWindow.PropertyNames.ControlName] = "cbStartDate"; this.WindowTitles.Add("Form1"); #endregion } #region Properties public WinComboBox UICbStartDateComboBox { get { if ((this.mUICbStartDateComboBox == null)) { this.mUICbStartDateComboBox = new WinComboBox(this); #region Search Criteria this.mUICbStartDateComboBox.SearchProperties[WinComboBox.PropertyNames.Name] = "cbStartDate"; this.mUICbStartDateComboBox.WindowTitles.Add("Form1"); #endregion } return this.mUICbStartDateComboBox; } } #endregion #region Fields private WinComboBox mUICbStartDateComboBox; #endregion } 

In bellow image, the control hierarchy is illustrated. It clearly shows the UICbStartDateWindow as parent for the ComboBox.

enter image description here

As you can see, the generated code should follow what is described in the link from Rasim Avci's answer.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.