Rasim Avci
Rasim Avci

Reputation: 63

ControlName does not work for idential Wincontrols in codedui

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."

Upvotes: 0

Views: 176

Answers (2)

PixelPlex
PixelPlex

Reputation: 794

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.

Upvotes: 1

Rasim Avci
Rasim Avci

Reputation: 63

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/

Upvotes: 1

Related Questions