1

出于某种原因,我在尝试从其父级定位 Window 子级时收到来自 White.Core 的运行时错误。

错误显示:

White.Core.Mappings.ControlDictionaryException: Could not find TestControl for ControlType=window and FrameworkId:Win32
at White.Core.Mappings.ControlDictionary.GetTestControlType(ControlType controlType, String frameWorkId, Boolean isNativeControl)
at White.Core.Mappings.ControlDictionary.GetTestType(String className, ControlType controlType, String frameworkId, String name, Boolean isNativeControl)
at White.Core.Mappings.ControlDictionary.GetTestType(AutomationElement automationElement)
at White.Core.Factory.DictionaryMappedItemFactory.Create(AutomationElement automationElement, ActionListener actionListener)
at White.Core.Factory.DictionaryMappedItemFactory.Create(AutomationElement automationElement, ActionListener actionListener, Type customItemType)
at White.Core.Factory.PrimaryUIItemFactory.Create(SearchCriteria searchCriteria, ActionListener actionListener)
at White.Core.UIItems.Container.NonCachedContainerItemFactory.Find(SearchCriteria searchCriteria)
at White.Core.UIItems.Container.ContainerItemFactory.Get(SearchCriteria searchCriteria, ActionListener uiItemActionListener)
at White.Core.Sessions.NullWindowSession.Get(ContainerItemFactory containerItemFactory, SearchCriteria searchCriteria, ActionListener actionListener)
at White.Core.UIItems.Container.CurrentContainerItemFactory.Find(SearchCriteria searchCriteria, WindowSession windowSession)
at White.Core.UIItems.UIItemContainer.Get(SearchCriteria searchCriteria)
--- End of inner exception stack trace ---
at White.Core.UIItems.UIItemContainer.Get(SearchCriteria searchCriteria)
at ICOWrapper.Form1.wasUserLoggedIn(String id1, String id2)
at ICOWrapper.Form1.button2_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

我正在尝试导航的当前结构如下:

主窗口->面板->窗口

我在 C# 中使用以下方法

        public Boolean wasUserLoggedIn(string id1, string id2)
    {
        Thread.Sleep(500);
        var mdiClient = window.MdiChild(SearchCriteria.ByControlType(ControlType.Pane).AndAutomationId(id1));
        Thread.Sleep(500);
        var selectPatient = (Window)mdiClient.Get(SearchCriteria.ByControlType(ControlType.Window).AndAutomationId(id2));
        Thread.Sleep(500);
        return selectPatient != null? true: false;
    }

并调用方法如下:

Boolean wasFound = wasUserLoggedIn("40960", "40961");

用于识别 ControlType 和 AutomationID 的 UIspy 对象:

AutomationId: 40960
ControlType: ControlType.Pane
Name: 
HelpText: 
Bounding rectangle: 8,78,900,581
ClassName: MDIClient
IsOffScreen: False
FrameworkId: Win32
ProcessId: 5964


AutomationId: 40961
ControlType: ControlType.Window
Name: Home
HelpText: 
Bounding rectangle: 8,59,900,600
ClassName: ClaWin01000000H_2
IsOffScreen: False
FrameworkId: Win32
ProcessId: 5964
4

2 回答 2

1

我建议升级到TestStack.White而不是旧的 White 库。

问题是你不应该用来.Get()解决windows。对于你应该使用的 MDI 应用程序MdiChild(),如果是modal窗口,请.ModalWindow()parent窗口上使用或返回应用程序然后使用Window()获取窗口。

希望有帮助

于 2013-09-26T09:03:36.293 回答
0

是不是Pane的后裔Window AutomationElement?您要查找的Window内容可能不在焦点上。

于 2013-07-10T18:52:35.350 回答