已锁定 Publish WPF custom control properties for Coded UI Tests

  • Tuesday, June 29, 2010 10:49 AM
     
     

    Hi,

    I'm writing a WPF custom control. Now I wanna publish some important properties for Coded UI testing purpose. My problem is that I do not know how to do it because I can not use the Automation providers (e.g. like IValueProvider - they all don't fit my needs)

    I read the  Gautam Goenka's "Series on Coded UI Test Extensibility" (http://blogs.msdn.com/b/gautamg/archive/2010/01/05/series-on-coded-ui-test-extensibility.aspx - very good by the way) and evaluated some code examples (NumericUpDown, Excel,...)

    I implemented a UITestExtensionPackage and a UITestPropertyProvider but in the UITestPropertyProvider's GetPropertyValue method I don't know how to get the main control instance and get (or set) the special properties.

    Any help would be appreciated!

    Thanks

    Michael

All Replies

  • Wednesday, June 30, 2010 1:20 AM
     
     

    If you are looking to get hold of the AutomationElement, you can do it by the following fashion.(Try a similar thing for SetPropertyValue as well.

    public abstract Object GetPropertyValue(UITestControl uiTestControl, string propertyName)

    {

    AutomationElement automationElement = (AutomationElement) uiTestControl.NativeElement;

    /// Your code

    }


    Please mark the post as answered if this answers your question. ThejK
  • Wednesday, June 30, 2010 8:34 AM
     
     

    Thank you for your quick answer!

    Exactly at this point my problem begins. How can I get the control's instance or the custom properties if I don't use the patterns???

    I saw that automationElement has a GetCurrentPropertyValue method. As far as I know I need an AutomationProperty - which I don't have. Or do I have to write my own?

    Thanks in advance!

    Michael

  • Wednesday, June 30, 2010 10:52 AM
     
     Proposed Answer

    Its not possible to get the WPF controls instance. I am not sure if you can work without using patterns. But if you want to work through patterns, gautam's numericUpDown example explains it. Check NumericUpDown.xaml.cs, line 222 over there.

    For a better response as to how to get properties from a custom wpf control, pose this question in the wpf forum


    Please mark the post as answered if this answers your question. ThejK
  • Wednesday, June 30, 2010 1:52 PM
     
     

    I guess the problem is not WPF specific.

    As I mentioned before the patterns do not fit. I've got a whole bunch of custom controls. They all (at least most of them) are very specific.

    Is there some kind of workaround?

    Does Microsoft plan to support testing of custom controls in future releases?

    Michael