[UWP]如何为应用程序的顶级窗口设置AutomationId? [英] [UWP] How can I set an AutomationId for the top level window of an app?

查看:108
本文介绍了[UWP]如何为应用程序的顶级窗口设置AutomationId?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对本地化的UWP应用程序进行一些编码的UI测试,并且在我的测试中使用本地化的Window Title来查找顶级窗口,这不是最佳的。

I am doing some coded UI test on a UWP app that is localized and the localized Window Title is used in my tests for finding the top level window, which is not optimal.

我真的想为顶级窗口/整个应用程序设置一个AutomationId,但我找不到办法做到这一点。

I would really like to set an AutomationId for the top level window / entire application, but I cannot find a way to do that.

任何人都知道如何在CoreWindow或其他地方设置AutomationId?

Anyone know how to set AutomationId on the CoreWindow or another place?

推荐答案

我能来的最接近的答案最好的是你可以在Window.Current.Content上设置AutomationId,因为它是从UIElement派生的。但是如果你将顶级窗口的Content属性更改为初始Frame
以外的其他东西,那么那会破坏。

The closest answer I could come up with is that you can set an AutomationId on Window.Current.Content since it is derived from UIElement. But if you change the Content property of your top level window to something other than it's initial Frame for some reason then that would break.

另一种选择,虽然复杂得多,但是解决方案是使用

Window.SetTitlebar
(有的是这里有一个示例:
https://github.com/Microsoft/Windows- universal-samples / tree / master / Samples / TitleBar
 ),以便您可以在自定义标题栏上设置AutomationId,然后使用它来到达顶级窗口。

An alternative, though much more complex, solution would be to create your own custom titlebar using Window.SetTitlebar (there's a sample here: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/TitleBar ) such that you could set an AutomationId on the custom titlebar and then use that to get to your top level window.


这篇关于[UWP]如何为应用程序的顶级窗口设置AutomationId?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆