简体   繁体   English

使用Windows Phone上的编码UI与MessageDialog进行交互

[英]Interact with MessageDialog using Coded UI on Windows Phone

I'm writing some Coded UI tests for a simple application and cannot seem to get the code to find or interact with a MessageDialog box. 我正在为一个简单的应用程序编写一些编码的UI测试,似乎无法获取代码来查找或与MessageDialog框进行交互。 Using the Test builder I am able to see the box, and its associated controls, but in the test I am unable to find anything but elements in the app. 使用“测试”构建器,我可以看到该框及其关联的控件,但是在测试中,除了应用程序中的元素之外,我什么都找不到。

I think the issue is that the XamlWindow that is being used for searching is limited to just the app under test, and the popup exists outside this context. 我认为问题在于,用于搜索的XamlWindow仅限于受测试的应用程序,而弹出窗口存在于此上下文之外。 I have tried to instantiate a new XamlWindow with the context that the popup exists in, but the code is unable to find any window except the app of the hardware buttons. 我试图用弹出窗口所在的上下文实例化一个新的XamlWindow,但是代码无法找到除硬件按钮的应用程序之外的任何窗口。

I have seen referenced in a few other places that the MessageDialog can be found when using a UIMap, but I am hand coding these tests and am trying to avoid their use when possible. 我已经看到在其他一些地方引用了在使用UIMap时可以找到MessageDialog的信息,但是我正在手工编写这些测试的代码,并在可能的情况下尝试避免使用它们。 I am not against using a UIMap if there is a way to generate it in code and load up the MessageDialog if that is possible. 我不反对使用UIMap,如果可以的话,可以使用代码生成它并加载MessageDialog。

After working with the automatically generated code I was able to figure out the answer. 使用自动生成的代码后,我能够找出答案。 In order to access the MessageDialog you need to instantiate the UITestControl referencing the popup window. 为了访问MessageDialog,您需要实例化引用弹出窗口的UITestControl。 The issue comes because this window is outside of the scope of the app being tested. 出现问题是因为此窗口不在被测试应用程序的范围之内。 I was able to instantiate a UITestControl object of this window using the following: 我可以使用以下方法实例化此窗口的UITestControl对象:

        UITestControl popupWindow = new UITestControl();
        popupWindow.TechnologyName = "UIA";
        popupWindow.SearchProperties[UITestControl.PropertyNames.ControlType] = "Window";
        popupWindow.SearchProperties["FrameworkId"] = "UIX";

The inportant difference between this and normal instantiation of a UITestControl object is that nothing is passed into the new. UITestControl对象的此实例与普通实例之间的重要区别在于,没有任何东西传递给新对象。 This allows the code to attach to an object outside of the scope of the tested app. 这允许代码将代码附加到测试应用程序范围之外的对象。 From here getting any element in the popup is the same as on a normal page, but instead of passing the testApp XamlWindow object you pass the popupWindow object. 从这里获取弹出窗口中的任何元素都与正常页面上的元素相同,但是您无需传递testApp XamlWindow对象,而是传递popupWindow对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM