UI自动化按钮样式启用 [英] UI Automation Button Style Enabled

查看:277
本文介绍了UI自动化按钮样式启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在评估UI测试UI自动化,我有以下定义的按钮,一个WPF应用程序:

I'm evaluating UI Automation for UI testing for that I have a WPF application with the following button defined:

<Button Style="{DynamicResource ButtonStyle}" x:Name="MyBtn"/>

当我需要在视觉上禁用按钮我只是改变了样式,以便用户知道该按钮被禁用(变色),但仍按钮被内部启用,所以我可以为了显示一个消息仍然启动OnClick事件时,在禁用按钮。

when I need to visually disable the button I just change the style so the user is aware that the button is disabled (the colour changed) but still the button is internally enabled so I can still launch the OnClick event in order to show a message when the user clicks on a "disabled" button.

现在的问题是,我不知道如何从UI自动化检查目前其应用,即当按钮被禁用或启用样式。吗?你知道我怎么能做到这一点。

Now the problem is that I don't know how to check from UI Automation the Style that its currently applied i.e. if the button is disabled or enabled. Do you know how can I do that?

在正常情况下,我应该做这样的事情:

In a normal situation I should do something like that:

Automation.Condition cEBtn = new PropertyCondition(AutomationElement.AutomationIdProperty, "MyBtn");

AutomationElement mybtnElement = appRegraceElement.FindFirst(TreeScope.Children, cEBtn);

bool disMyBtn = (bool)mybtnElement .GetCurrentPropertyValue(AutomationElement.IsEnabledProperty);



但在我的情况下,按钮总是因此使我需要检查应用到按钮的样式。

but in my case the button is always enabled therefore I need to check the Style applied to the button.

非常感谢你。

最好的问候

推荐答案

作为评论在这个环节:
http://social.msdn.microsoft.com/Forums/en/windowsaccessibilityandautomation/thread/129d2ea6-91ae-4f65-b07e-c36684ae742b

as commented in this link: http://social.msdn.microsoft.com/Forums/en/windowsaccessibilityandautomation/thread/129d2ea6-91ae-4f65-b07e-c36684ae742b

WPF属性不能(还)暴露成自动化的特性。尽管如此,迈克尔提出了一个解决方法。我会离开这里,以防万一是有用的人。

WPF properties cannot be (yet) exposed as Automation properties. Nevertheless, Michael proposes a workaround. I'll leave it here just in case is useful for someone.

<Style TargetType="Button">
    <Setter Property="AutomationProperties.ItemStatus"
        Value="{Binding RelativeSource={RelativeSource Self}, Path=Style}" />
</Style>



,你可以看到我们在这里做的是揭露(所有按钮)WPF属性样式使用自动化财产ItemStatus。那么这种风格可以从UI自动化客户端一样,可以得到:

as you can see what we are doing here is to expose (for all the buttons) the WPF property Style using the Automation property ItemStatus. Then this Style can be obtained from UI Automation client like that:

Automation.Condition cEBtn = new PropertyCondition(AutomationElement.AutomationIdProperty, "MyBtn");
AutomationElement mybtnElement = appRegraceElement.FindFirst(TreeScope.Children, cEBtn);
string a = (string)mybtnElement.GetCurrentPropertyValue(AutomationElement.ItemStatusProperty);



作为一种解决方法它的确定对我来说,但它有两个问题,要求我更新应用程序代码,不应该是在测试过程中必要的,它只能暴露在一个时间一个属性。

as a workaround its ok for me, but it has two problems, it requires me to update the application code, should not be necessary during testing, AND it can only expose one property at a time.

最好的问候,
维克托

Best regards, Víctor

这篇关于UI自动化按钮样式启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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