如何获取 White.Core.UIItems.WindowItems.Window 的实例,它可以自动化在集成测试中创建的 WPF 窗口?
我使用 White 自动化框架创建了一个集成测试。这是集成测试的开始:
var app = Application.Launch("WPFIntegrationTest.exe");
var window = app.GetWindow("MainWindow");
但是,我希望获得 White.Core.UIItems.WindowItems.Window
的实例,而无需在新进程中“启动”应用程序。然后,这将允许我注入 MainWindow 具有的任何依赖项,以便我可以有选择地模拟/存根它们。
作为我正在寻找的示例,这是我希望可以编写的代码:
var myWindow = new MainWindow();
var window = White.Core.UIItems.WindowItems.Window(myWindow);
有什么方法可以使用 White 自动化框架来实现此目的吗?
I have created an integration test using the White automation framework. This is the start of the integration test:
var app = Application.Launch("WPFIntegrationTest.exe");
var window = app.GetWindow("MainWindow");
However, I would like to get an instance of White.Core.UIItems.WindowItems.Window
without 'launching' the application in a new process. This would then allow me to inject any dependencies that MainWindow
has, so that I can selectively mock/stub them out.
As an example of what I'm looking for, this is the code I wish I could write:
var myWindow = new MainWindow();
var window = White.Core.UIItems.WindowItems.Window(myWindow);
Is there any way I can achieve this using the White automation framework?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您所描述的是在同一进程中运行白色测试代码和被测应用程序 - 是这样吗?
据我所知,白人作者不鼓励这样做 - 请参阅此白人常见问题解答页面上的问题 #9:
http://white.codeplex.com/wikipage?title=Other%20questions
不过,也许下面的文章将帮助您做您想做的事:
http://msdn .microsoft.com/en-us/magazine/cc163864.aspx
在上面的文章中,检查“图 5 - 启动应用程序”中的代码。
作者的方法似乎有点像您所描述的 - 他的代码似乎加载一个程序集,使用它创建 Form 对象的实例,然后启动一个单独的线程,在该线程中调用 Application.Run 来启动 Form。
一旦 AUT 运行,您应该能够在主线程中使用 White 附加它。
也许该技术会让您开始按照您希望的方式操纵 AUT?
为了方便起见,这里使用文章中的图 5:
It sounds like what you're describing is running your White test code and the application under test in the same process - is that the case?
From what I can tell the White author discourages that - see question #9 on this White FAQ page:
http://white.codeplex.com/wikipage?title=Other%20questions
Still, maybe the article below will help you do what you want:
http://msdn.microsoft.com/en-us/magazine/cc163864.aspx
In the above article, check the code in "Figure 5 - Launching the App".
The author's approach seems a little like what you're describing - his code appears to load an assembly, use it to create an instance of a Form object, then launch a separate thread in which Application.Run is called to launch the Form.
Once your AUT is running, you should be able to attach to it using White in the main thread.
Perhaps that technique will get you started on manipulating the AUT the way you were hoping to do?
Just for convenience here's Figure 5 from the article: