与应用程序的codeD UI多个实例交互 [英] Interacting with multiple instances of an application in Coded UI

查看:281
本文介绍了与应用程序的codeD UI多个实例交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我面临的情况是,我想编写一个测试,将使用codeD的用户界面与同一应用程序的多个实例进行交互,在这种情况下,Microsoft Excel中。换句话说,将有多个Excel工作簿中打开多个窗口,并且我需要能够直接$ C $光盘的UI编程与特定实例进行交互。我最初以为这种类型的实例的管理将是 ApplicationUnderTest 类的功能,但不是很明显这个类将如何实现这一目标。

的相互作用将涉及相同的UIMap所有实例(事实上,每个实例可能需要多个UIMaps,但为简单起见,可以忽略这个问题,除非它是显著的回答)。

一对夫妇的解决方案接近我已经意识到了:

  • 最小化和最大化实例所以只有当前正在使用的一个是在任何给定时间可见。理想情况下,我想避免这种情况。一方面,它可能最终成为一个要求,即两个窗口在测试过程中是可见的同时。
  • 动态修改搜索属性始终包括一些独特标识符每次UI地图的访问时间。我不知道什么搜索属性的最佳人选会在这里。

在理想情况下,我想更多的东西融入codeD的用户界面比这些选项之一,尽管后者可能会在必要时足够了。我想AP preciate是否还有其他可能的方法的任何方向。

解决方案

您可以尝试创建用户界面的控制(在的UIMap生成的类)的多个实例,并为他们树立一个实例搜索属性(如果您有任何其他独特的搜索属性,你可以使用这些太)。你只需要设置这些在试验开始

我用计算器这个例子。它应该是Namespace.UIControl和不UIMap.UIControl。你需要的类而不是属性。

  VAR A1 =新UICalculatorWindow();
a1.SearchProperties [实例] =1;
VAR A2 =新UICalculatorWindow();
a2.SearchProperties [实例] =2;
a1.Find();
a2.Find();
 

找到这些窗口的窗口句柄将控制对象相关联后,所以你不必担心他们的订单了。

另一个解决方案是获得通过PInvoke的功能,目前所有的窗口句柄,过滤这些得到你想要的窗口,然后使用 UITestControlFactory 来创建控件。


编辑:您也可以使用FindMatchingControls方法

  VAR一个=新UICalculatorWindow()FindMatchingControls()。
 

然后就可以从返回的列表中获取实时控制。这些解决方案都有点变通十岁上下,但我不认为这可以在的UIMap层面来解决,除非该控件的所有实例都记录为独特的UI控件。


编辑:CUIT在窗口的列表中搜索处理它从WINAPI调用得到( EnumWindows的),默认情况下它匹配给定列表中返回的第一个窗口搜索属性。如果实例属性被设置,那么它跳过第一n-1个窗口(即符合搜索条件),并让你的第n个窗口。

当你调用查找() UITestControl 将一个窗口搜索与给定的搜索属性和如果发现窗口 UITestControl 有一个参考,该窗口的窗口句柄或的AccessibleObject 从该窗口了。

窗口句柄的顺序,如果你设置集中到一个窗口,这将是更接近列表的开始可以改变pretty的时候,例如。所以,当你把所有的窗户打开,你应该创建 UITestControl S,设置实例属性并调用查找()对所有的人,使他们不试运行期间混淆了。

如果您发现实例设置为1,然后混淆了窗口的顺序那么当你的窗口搜索与一个窗口实例设置为2,你可能会发现你已经找到了窗口,结束了两个 UITestControl 取值设置为相同的窗口。

我不知道如何 OrderOfInvocation 的作品,我无法得到它的工作还没有。

The scenario that I am facing is that I am trying to write a single test which will use Coded UI to interact with multiple instances of the same application, in this case Microsoft Excel. In other words, there will be multiple Excel workbooks open in multiple windows, and I need to be able to direct Coded UI to interact with a specific instance programatically. I initially thought this type of instance management would be a function of the ApplicationUnderTest class, but it is not obvious how this class would achieve this.

The interactions will involve the same UIMap for all instances (in fact, each instance will probably need multiple UIMaps, but for the sake of simplicity that can be ignored for this question unless it is significant to the answer).

A couple of solution approaches I'm already aware of:

  • Minimize and maximize the instances so only the one currently being used is visible at any given time. Ideally I'd like to avoid this. For one thing, it may eventually become a requirement that two windows are visible simultaneously during the tests.
  • Dynamically modify the search properties to always include some unique identifier every time the UI Map is accessed. I'm not sure what the best candidate for a search property would be here.

Ideally I would like something more integrated into Coded UI than either of these options, though the latter would probably suffice if necessary. I would appreciate any direction on whether there are any other possible approaches.

解决方案

You could try creating multiple instances of the ui control (the class generated in the UIMap) and set an Instance search property for them (if you have any other unique search properties you can use those too). You only need to set these at the start of the test.

I used a calculator for this example. It should be Namespace.UIControl and not UIMap.UIControl. You need the class not the property.

var a1 = new UICalculatorWindow();
a1.SearchProperties["Instance"] = "1";
var a2 = new UICalculatorWindow();
a2.SearchProperties["Instance"] = "2";
a1.Find();
a2.Find();

After finding these windows their window handle will be associated with the control object so you don't have to worry about their order anymore.

Another solution would be to get all current window handles via a pinvoke function, filter these to get the windows you want, then use the UITestControlFactory to create your controls.


Edit: or you can use the FindMatchingControls method.

var a = new UICalculatorWindow().FindMatchingControls();

Then you can get the live controls from the returned list. These solutions are a bit workaround-ish but I don't think this can be solved on the UIMap level unless all instances of the control are recorded as unique ui controls.


Edit: CUIT searches in the list of window handles it gets from a WinApi call (EnumWindows) and by default it returns the first window from the list that matches the given search properties. If the Instance property is set then it skips the first n-1 windows (that matches the search criteria) and gets you the n-th window.

When you call Find() on a UITestControl it will search for a window with the given search properties and if a window is found the UITestControl keeps a reference to that window's window handle or the AccessibleObject it got from that window.

The order of window handles can change pretty often, for example if you set focus to a window it will be closer to beginning of the list. So when you have all your windows open you should create the UITestControls, set the Instance property and call Find() on all of them so they don't mix up during the test run.

If you find a window with Instance set to 1 and then mix up the order of the windows then when you search for a window with Instance set to 2 you might find the window you already found, ending up with two UITestControls set to the same window.

I have no idea how OrderOfInvocation works, I couldn't get it to work yet.

这篇关于与应用程序的codeD UI多个实例交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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