WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

Custom attributes/properties in WinAppDriver.

Open kfertitta opened this issue 11 months ago • 5 comments

I'm testing a WPF app and have tried exposing some public properties from my custom control AutomationPeer classes. The goal is to enable our UI tests to call GetProperty/GetAttribute to infer some additional context about the element. In my attempts thus far, GetProperty throws an exception and GetAttribute returns null.

Is there a way to do this?

kfertitta avatar Jan 25 '25 12:01 kfertitta

check https://learn.microsoft.com/en-us/dotnet/api/system.windows.automation.automationproperties?view=windowsdesktop-9.0

anunay1 avatar Jan 27 '25 15:01 anunay1

Thanks @anunay1 . That's useful and it works. Tested ItemType by overriding GetItemTypeCore in my automation peer class and binding it to a property in my view model. I was then able to get that value via AppiumWebElement.GetAttribute("ItemType").

I was originally asking if the set of retrievable attributes could be expanded to something arbitrary instead of those values on AutomationProperties. But, I think for my current purposes, I can just hijack the ItemType property and put my own custom data there.

Do you see any issues with hijacking ItemType to hold arbitrary text that is meaningful only in my application (or is that its actual intended usage)?

Thanks again.

kfertitta avatar Jan 27 '25 16:01 kfertitta

I don't see any issue in highjacking as long as it's shown in inspect.exe. And in visual studio there is an option to enable automation properties some checkbox please check . It's very helpful as you don't need to write code manually.

anunay1 avatar Jan 27 '25 16:01 anunay1

Sorry, but you lost me with that last bit. I'm not sure what that setting is or what it enables. I also don't understand how I don't have to write any code manually. I don't have to write much for our custom controls -- just a single override. Not sure how Visual Studio itself would know about domain-specific ItemType data we need to surface. We have a bunch of WPF controls embedded within our VSIX in Visual Studio. Our product integrates with Visual Studio itself, so we have a need to automation some of the native VS controls, like Solution Explorer, and that's pretty easy. But, we also have a need to surface automation data for our own controls.

Just wanna make sure I'm not missing something you're trying to emphasize.

kfertitta avatar Jan 27 '25 17:01 kfertitta

Leave it seems like they have removed that option in latest versions of visual studio

anunay1 avatar Jan 28 '25 05:01 anunay1