2

I've been tasked to find out how to implement UI automation for desktop apps with appium-dotnet-driver. I've successfully managed to use the windows calculator app for UI unit testing.

That being said, having a lot of trouble with my company's winforms app because some elements either don't have an AutomationId or it changes every time something is clicked on the program.

Is there an easy way to define the AutomationId for a control type (i.e. Button)?

askepott
  • 250
  • 3
  • 13

1 Answers1

1

Solved by setting the Name property of relevant controls. AutomationId is automatically inferred from Name or Text properties. Hope it helps someone.

askepott
  • 250
  • 3
  • 13
  • Another interesting feature is the [Control.AccessibilityObject](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.accessibilityobject). It provide useful properties. It does not include the Control's Handle, though. You need to cast the `[Control].AccessibilityObject` to [Control.ControlAccessibleObject](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.controlaccessibleobject) for that: `IntPtr ctlHandle = ([Control].AccessibilityObject as Control.ControlAccessibleObject).Handle;` – Jimi May 09 '19 at 13:43
  • Sample code here: [Run event when any Form loads](https://stackoverflow.com/a/55960110/7444103). – Jimi May 09 '19 at 13:45
  • Could you explain how that is relevant to my question? After looking at your example it's not immediately clear. Thanks! – askepott May 09 '19 at 14:47
  • *How to identify a winforms button control that has no AutomationId?*. Using its Handle. Or other properties: `KeyboardShortcut`, `Parent` `Bounds` etc. It also allows to call directly the DefaultAction without `InvokePattern`. – Jimi May 09 '19 at 14:51