1

Is there a way how to access custom property on custom control in WPF using White framework test ?

Let's say I have class like this:

public class MyButton : System.Windows.Controls.Button
{
    public MyButton()
    {

    }

    public string MyCustomButtonProp { get { return "MyButtonInfo"; } }
}

Is there a way how to access MyCustomButtonProp via White framework in a test ? I read how custom controls are handled (https://teststackwhite.readthedocs.io/en/latest/AdvancedTopics/CustomUIItems/) but that didn't lead me to conclusion how to access custom properties, only how to handle custom controls with nested controls. If I use standard White framework objects (Button in this case) I can interact with the button but that's not sufficient in my case.

user1275513
  • 357
  • 2
  • 8

1 Answers1

0

You would need to write your own AutomationPeer to expose the property. Then you would need to extend the White control to expose your custom property.

Overriding the AutomationPeer is not that bad since you might be able to just inherit from another AutomationPeer to get 90% of the functionality you need.

Here is an example of how to write a AutomationPeer. Here is another document I would take a look at which gives a much more broad overview of implementing the "server" side of UIA.

Max Young
  • 1,522
  • 1
  • 16
  • 42
  • I have read the articles (Google cache: https://webcache.googleusercontent.com/search?q=cache:_Ym2h2FveUMJ:https://blogs.msdn.microsoft.com/patrickdanino/2009/11/11/custom-controls-and-ui-automation/+&cd=1&hl=de&ct=clnk&gl=in&client=firefox-b) but I could not solve my problem. Maybe you could have a look at it: https://stackoverflow.com/questions/53500604/teststack-how-to-find-custom-controls-and-invoke-methods-fire-events?noredirect=1#comment93870793_53500604 – Dominic Jonas Nov 28 '18 at 07:02
  • @dominicjonas I will take a look at this soon because more than likely I will be attempting to add a custom field and pattern to a control at work soon. – Max Young Dec 01 '18 at 21:12
  • 1
    @dominicjonas you may also find this interesting, a developer on teststack.white sent it to me a while ago and it helped me better understand the framework I was working in https://github.com/TestStack/uia-custom-pattern-managed/blob/master/README.md – Max Young Dec 01 '18 at 21:20
  • Thanks for your reply! It looks like that's exactly what I was looking for! – Dominic Jonas Dec 03 '18 at 07:53