CUIT does not recognise controls under a Tab control when 'Visibility' property of tab item is set to 'Collapsed'

Locked CUIT does not recognise controls under a Tab control when 'Visibility' property of tab item is set to 'Collapsed'

  • Monday, April 16, 2012 7:00 AM
     
     

    Hi,

    I have a WPF application which contains multiple tabs and the tab items have different controls under them. When I set the Visibility property on tabitems to 'Collapsed', CUIT is not able to recognise internal controls under that tab.

    Someone please help me in solving this issue.

    Thanks,

    Sirisha


    sirisha

All Replies

  • Tuesday, April 17, 2012 10:11 AM
    Moderator
     
      Has Code

    Hi Sirisha,

    I guess this is a reasonable behavior in Coded UI Test, Tab control contains other control in application, so if this control is invisible then all the controls in it would not be visible for user or Coded UI Record engine.

    You could prove this by following statement in Immediate Window, you would see the result is 0 after the TabItem2’s Visibility=”Collapsed".

    this.UIMainWindowWindow.UITabControl1TabList.UITabItem2TabPage.GetChildren().Count;
    --> 0
    

    Hope this could help you.



    Tony Xiao [MSFT]
    MSDN Community Support | Feedback to us

  • Wednesday, April 18, 2012 4:28 AM
     
     

    Hi Tony,

    Even though the tab item's visibility is set to 'Collapsed', I cans till see and access the controls under the tab item. But when I tried to automate the window using Coded UI, it fails to recognise the controls.

    So, does Coded UI fail to get hold of the child controls if the parent controls visibility is set to collapsed?

    Thanks,

    Sirisha


    sirisha


    • Edited by Sirisha M Wednesday, April 18, 2012 9:43 AM
    •  
  • Thursday, April 19, 2012 10:42 AM
    Moderator
     
     

    Hi Sirisha,

    I would like to know what is the control looks like after the tab item’s visibility is set to ‘Collapsed’ or could please you share us a screenshot about this?


    Tony Xiao [MSFT]
    MSDN Community Support | Feedback to us

  • Thursday, April 19, 2012 1:10 PM
     
     

    Hi Jack,

    I have the following tab control with two tabitems:

    I have set the visibility property for the first tab i.e 'Smart UI Test' tab to 'Collapsed' and after that I  still see the controls in the first tab as follows:

    I can do the required actions on the first tab control. But when I am actually trying to automate those actions, CUIT is failing to recognise them.

    Thanks,

    Sirisha


    sirisha

  • Friday, April 20, 2012 8:59 AM
    Moderator
     
     Answered

    Hi Sirisha,

    As what I have try, I did reproduced this issue locally, and as far as I know this behavior is by design in WPF, but Coded UI Test would fail as FailedToPerformActionOnBlockedControlException, so from the error shows that Coded UI would not perform actions on the control which is not visible by logic regardless its real presentation.

    I would suggest that you could report this case from here:

    Consider into this issue, I would like to know what is your requirement against setting Visibility, I guess there might be another way could achieve what you want.


    Tony Xiao [MSFT]
    MSDN Community Support | Feedback to us

  • Friday, April 20, 2012 1:00 PM
     
     

    Thanks for the follow up.

    This was done to implement a wizard. Basically tabs having different content will be displayed one by one for next button clicks. We didn't want to display tab headers. So this property was used for that purpose.

    Do we have any alternatives other than rewriting the wizard with different approach?

    Thanks,

    Sirisha


    sirisha

  • Monday, April 23, 2012 8:27 AM
     
     Answered

    Hi Sirisha,

    To workaround the issue, I would suggest using a ListView to replace the TabControl since you don't want to show the header at all.

    You can set ScrollViewer.CanContentScroll to true to disable the pixel scrolling.

    Set ScrollViewer.HorizontalScrollBarVisibility and ScrollViewer.VerticalScrollBarVisibility to Hidden to hide the scroll bars.

    Then you can call ListView's BringIntoView method programmatically to navigate among items.

    If you have any question about the workaround details, please open a new thread in the WPF forum for further support. In the new thread, you can add a link to this thread to provide the background information.

    At last, for your original question, it looks like a CUIT issue to me. I suggest reporting this issue on the connect portal in Tony's post so the product team can investigate this issue.

    Have a nice day!


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us

  • Tuesday, May 01, 2012 9:13 AM
    Moderator
     
     

    Hi

    What if you try to record the scenario with keyboard only. Does that work?


    Thanks & Regards Siddhartha

  • Wednesday, May 02, 2012 7:11 AM
     
     

    Siddhartha,

    The keyboard actions are recorded on the tab item not on the controls inside the tab control. I should be able to record actions on the controls inside the tab item.

    Thanks,

    Sirisha


    sirisha

  • Wednesday, May 02, 2012 7:15 AM
     
     

    Siddhartha,

    I can provide the sample application where the problem can be reproduced.

    Please let me know what you think of it.

    Thanks,

    Sirisha.


    sirisha

  • Wednesday, May 02, 2012 8:03 AM
    Moderator
     
     Answered
    That will be great. Can you mail me the repro app?

    Thanks & Regards Siddhartha

    • Marked As Answer by Sirisha M Thursday, May 03, 2012 1:38 PM
    •  
  • Wednesday, May 02, 2012 11:29 AM
     
     

    Siddhartha,

    I have mailed the sample application.

    Thanks,

    Sirisha


    sirisha

  • Thursday, May 03, 2012 12:13 PM
     
     

    Siddhartha,

    Thanks for the help.

    It was working for the sample application.

    I will test the fix on the main application and let you know the status.

    Thanks again.

    Sirisha.


    sirisha

  • Friday, May 04, 2012 6:22 AM
    Moderator
     
     Proposed Answer Has Code

    Hi,

    Just to update others.

    Codeduitest depends on UIA to record and identify the WPF controls. In this case it looks like there is an optimization in WPF UIA implementation where if a control has Visibility = Collapsed it does not drill down to get the actual element from point. I wrote a small custom TabItem class which makes sure we get proper Element from point.

    namespace TabItemProblem
    {
        using System.Windows;
        using System.Windows.Automation.Peers;
        using System.Windows.Controls;
    
        /// <summary>
        /// Custom TabItem class. It is used for cases where VisibilityProperty is set to collapsed and when the UI is automated.
        /// </summary>
        public class TabItemCustom : TabItem
        {
            /// <summary>
            /// Returns a custom automation peer which returns modified values for few properties.
            /// </summary>
            /// <returns>The AutomationPeer.</returns>
            protected override AutomationPeer OnCreateAutomationPeer()
            {
                if (this.peer == null)
                {
                    this.peer = new TabItemCustomPeer(this.Parent, (TabControlAutomationPeer)TabControlAutomationPeer.CreatePeerForElement(this.Parent as UIElement), this);
                }
                return peer;
            }
    
            private TabItemCustomPeer peer = null;
        }
    
        /// <summary>
        /// This class is a custom class for AutomationPeer of TabItem. It is used for tabitem who's Visibility property is set to Collapsed, but has
        /// children in it. AutomationElement.FromPoint does not work in such cases. Overriding some of these properties make sure that Automation work well.
        /// </summary>
        public class TabItemCustomPeer : TabItemAutomationPeer
        {
            public TabItemCustomPeer(object owner, TabControlAutomationPeer peer, TabItemCustom tabItem)
                : base(owner, peer)
            {
                this.tabItemCustom = tabItem;
            }
    
            /// <summary>
            /// Returns the AutomationId of the control.
            /// </summary>
            /// <returns>The automationId of the string.</returns>
            protected override string GetAutomationIdCore()
            {
                return this.tabItemCustom.Name;
            }
    
            /// <summary>
            /// Gets the IsOffscreenProperty. Below method returns false so that AutomationElement.FromPoint works well for controls inside the TabItem.
            /// </summary>
            /// <returns>True if offscreen.</returns>
            protected override bool IsOffscreenCore()
            {
                return false;
            }
    
            /// <summary>
            /// Gets the bounding rectangle for tabitem.
            /// </summary>
            /// <returns>The bounding rectangle of the control.</returns>
            protected override Rect GetBoundingRectangleCore()
            {
                return new Rect();
            }
    
            /// <summary>
            /// Returns the item status of the control.
            /// </summary>
            /// <returns>The item status property.</returns>
            protected override string GetItemStatusCore()
            {
                return "";
            }
    
            /// <summary>
            /// Returns the IsEnabled property.
            /// </summary>
            /// <returns>The IsEnabled property.</returns>
            protected override bool IsEnabledCore()
            {
                return false;
            }
    
            private TabItemCustom tabItemCustom;
        }
    }
    

    if the the application you use the above TabItemCustom class instead of TabItem class things will work as expected.


    Thanks & Regards Siddhartha