Can't get CustomUIItem to work

Jul 8, 2011 at 5:09 AM
Edited Jul 8, 2011 at 5:12 AM

I have followed the docs and samples to create a new CustomUIItem for my WPF ValidationSummary and cannot get it to work.

ValidationSummary inherits from UserControl now, originally it inherited from Control but I changed it to match the sample when my first find attempt did not work.

The instance I am trying to find has both an x:Name (added while trying to get it to work) and an AutomationId, both are ValidationSummary

At the moment my CustomUIItem does nothing and has no properties, these will be added if/when I get it to work.

[ControlTypeMapping(CustomUIItemType.Pane)]
public class ValidationSummary: CustomUIItem
{
  protected ValidationSummary(){}
  public ValidationSummary(AutomationElement element, ActionListener actionListener)
  :base (element, actionListener) {}
}

I have also tried CustomUIItemType.Custom

In my Screen I have a property for the ValidationSummary defined like this

public  ValidationSummary ValidationSummary
{
 
get
 
{
   
return this.Window.Get<ValidationSummary>(SearchCriteria.ByAutomationId(this.GetMemberName(() => this.ValidationSummary)));
  }
}

But this always returns null.

If I change the Get<> to the Get I am returned an IUIItem for the control without any problem, and in debug I can see it is the correct control.  So it is only when White applies the Type criteria that it fails to find it.

What am I doing wrong?

 

 

 

  

 

 

 

 

 

 

Coordinator
Jul 10, 2011 at 5:52 AM

what is the control type of the automation element you are trying to find?

Jul 10, 2011 at 7:25 AM

It is a WPF custom control that orginally derived from Control.

Originally when I created my CustomUIItem I set the ControlTypeMapping to CustomUIItemType.Custom, which seemed the obvious thing to do.  When it didn't work I looked at your documentation and sample and changed the control to derive from UserControl and changed to CustemUIItemType.Pane as shown in the code included in my original post.

As far as I can see I have done everything you suggest except add a new mapping in your source code, but to be honest having seen that you have every ControlType in the UI Automation library mapped I don't see how adding another mapping helps.

Mike 

Jul 11, 2011 at 12:48 PM

 

Control don't implement Automation Peer.. UIAutomation can't see this element.

 

Throndorin

Jul 11, 2011 at 5:11 PM

So are you saying that in order for White to be able to return my ValidationSummary as a CustomUIItem, I have to create an AutomationPeer for my custom control.  There is no indication of this requirement in the White docs.

I can use White to return the item as IUIItem, and I can happily get it as a AutomationElement using System.Windows.Automation API.  So UIAutomation can see my control as an element, I was expecting White to take care of wrapping it as a CustomUIItem.

For this personal project I have abandoned White, but I am curious how to properly use CustomUIItem in case I end up using it professionally on a contract. 

Coordinator
Jul 12, 2011 at 11:33 AM

You would have to launch UI Spy to find out what is the control type (property) of the automation element. These are different from type of controls for WPF.

Jul 12, 2011 at 9:37 PM

I have done that and as I assumed it would UISpy shows ControlType.Custom, which as I mentioned was what I originally set my ControlTypeMapping to.  I only changed it when White couldn't find my control and saw your sample was set to CustomUIItemType.Pane.  I have tried again with it set to Custom and the test still fails to find the control.  I am wondering if I need to do some kind of refresh before attempting the find, because at the time my Screen is loaded the ValidationSummary is not visible, it only becomes visible when the user submits an invalid form.  However I would find this strange because for WPF UIAutomation finds the control happily but has a value for the AutomationElement.IsOffScreenProperty of true, which changes to false once the control becomes visible.  Does White do something different that causes it to return null for a WPF control that has Visibility = Collapsed?

Jul 13, 2011 at 6:13 AM
Edited Jul 13, 2011 at 6:15 AM
MikeHanson wrote:

So are you saying that in order for White to be able to return my ValidationSummary as a CustomUIItem, I have to create an AutomationPeer for my custom control.  There is no indication of this requirement in the White docs.

I can use White to return the item as IUIItem, and I can happily get it as a AutomationElement using System.Windows.Automation API.  So UIAutomation can see my control as an element, I was expecting White to take care of wrapping it as a CustomUIItem.

For this personal project I have abandoned White, but I am curious how to properly use CustomUIItem in case I end up using it professionally on a contract. 

That was only my first idea, I have had the same problem and our developer fix this.

 so we can test this control now.

In my tests I use the way over the AutomationElement#

 

AutomationElement element = parent.GetElement(SearchCriteria.ByAutomationID("myElement")); 
MyCustomUIItem item = new MyCustomUIItem(element, parent.ActionListener)

 

Using this I get CustomUIItems in all cases.

Jul 13, 2011 at 5:56 PM

I understand and thanks a lot for trying to help.  Doing it the the way you have done isn't much different to creating any old class and passing the element to it as a wrapper.  I thought the point of the CustomUIItem was that you can then do Find<MyCustomUIItem>() and let White do the wrapping.  I was hoping it works the way WebAii does for Silverlight.  There if I create a class that matches the element name in XAML and inherit from the WebAii FrameworkElement I can do Find<MyWrapper>() and it works every time.

Coordinator
Jul 18, 2011 at 4:03 PM

Is it possible to post failing test which I can run to find out what the issue is?