简体   繁体   中英

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. 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. 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.

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. 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.

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. 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 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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