在CodedUI中声明自定义WPF控件的自定义属性时出现InvalidCastException
您好,
我们希望能够在我们的CodedUI测试中断言我们应用程序中自定义WPF控件的某些自定义属性。
We want to be able to assert in our CodedUI tests on some custom properties from custom WPF controls in our application.
由于CodedUI不支持开箱即用,我正在查看互联网上提供的信息和示例。关于这个主题的一篇好文章来自Mathew Aniyan的博客:
Because this is not supported out of the box by CodedUI, I was looking into information and examples available on the internet. One good article on this subject is from Mathew Aniyan's blog:
http://blogs.msdn.com/b/mathew_aniyan/archive/2011/05/17/custom-wpf-control-s-custom-properties.aspx
我下载了属于此示例的代码,并尝试启动并运行该代码。首先,我构建并安装了扩展。接下来,我做了一个简单的CodedUI测试,尝试在示例
WPF应用程序中验证自定义AnimatedButton中的自定义属性。
I downloaded the code belonging to this example, and tried to get it up and running. First I build and installed the extension. Next I made a simple CodedUI test that tries to verify the custom properties in the custom AnimatedButton in the example WPF application.
我看到的非常好用的是我可以从Coded UI测试构建器的"添加断言"对话框中的AnimatedButton中选择和添加自定义属性的断言。但是,当我使用添加的断言运行我的CodedUI测试时,
因InvalidCastException而失败。它在AnimatedButton.cs的属性AnimatedStartColor中跟随语句失败:
What I see that works very nicely is that I can select and add assertions on the custom properties from the AnimatedButton in the 'Add assertion' dialog box from the Coded UI test builder. However, when I run my CodedUI test with the added assertions, it fails with an InvalidCastException. It fails on following statement in property AnimatedStartColor from AnimatedButton.cs:
从字符串到Color的转换导致InvalidCastException。这是正常的.NET行为(你不能以这种方式将字符串转换为Color对象),所以我不明白它是如何工作的
The cast from a string to a Color is resulting in the InvalidCastException. This is normal .NET behavior (you cannot cast a string this way to a Color object), so I do not understand how this can work at all.
所以,我的问题,我做错了什么,在这种情况下,什么?有没有人设法让这个示例扩展运行?
So, my question, do I do something wrong, in that case, what? Did anybody manage to get this sample extension running?
有关我的环境的一些信息:
Some info on my environment:
- 安装了Feature Pack 2的Visual Studio 2010 Premium
- .NET 4.0
感谢任何帮助!
谢谢,
Jan Lavrijsen
Jan Lavrijsen
大家好,
到目前为止我的问题没有反应......
No reactions so far on my question...
让我尝试更一般地提出问题:
Let me try to ask the questions more general:
是否有人使用CodedUI成功断言自定义wpf控件的自定义属性?
Did anyone succeed in asserting custom properties of custom wpf controls using CodedUI?
如果是,您是否有链接t关于它的工作实例或信息?
If yes, do you have a link to a working example or information on it?
关于无效广播问题的详细信息,是从属性中获取实际对象(如颜色或持续时间)可能或者我应该尝试获取 ToString值并对其进行测试?
More into detail on the invalidcast problem, is getting the actual object from a property (like Color or Duration) possible or should I just try to fetch the ToString value and test on that?
谢谢,Jan