简体   繁体   English

C#Teststack.White自动化Winforms菜单(ControlType.Menu),它不是主窗口的子级

[英]C# Teststack.White automating Winforms Menu (ControlType.Menu) which is not child of the main window

I am automating a legacy WinForms application using Teststack.White , and I've encountered a problem. 我正在使用Teststack.White自动化旧版WinForms应用程序,但遇到了问题。 The menu which shows-up after right-clicking some item, for some reason appears to be outside the main application window in UI Hierarchy: 右键单击某些项目后,由于某种原因而显示的菜单似乎在UI层次结构的主应用程序窗口之外

VisualUIVerify UI层次结构

What is the best way to approach automating this menu? 自动化此菜单的最佳方法是什么? Our test framework is build around a window hierarchy, and we access items which are children of the main application window. 我们的测试框架是围绕窗口层次结构构建的,并且我们访问作为主应用程序窗口的子级的项。

Right now we approach this problem by using Keyboard arrows to select menu items and clicking Enter (which is not the best solution, I suppose). 现在,我们通过使用键盘上的箭头选择菜单项并单击Enter (我认为这不是最佳解决方案)来解决此问题。

Is there a better way to solve this in Teststack.White? 有没有更好的方法来解决此问题在Teststack.White中? Thank you! 谢谢!

You can find the right click menu if you search under all desktop windows. 如果在所有桌面窗口下搜索,则可以找到右键单击菜单。 See code below: 参见下面的代码:

//Call the function GetCurrentPopUpMenu //调用函数GetCurrentPopUpMenu

        PopUpMenu pop = GetCurrentPopUpMenu();

        pop.Item("Add Child").Click();

//The GetCurrentPopUpMenu function // GetCurrentPopUpMenu函数

    PopUpMenu GetCurrentPopUpMenu()
    {
        List<Window> windows = WindowFactory.Desktop.DesktopWindows();
        foreach (Window w in windows)
        {
            if (w.Name == "") return w.Popup;
        }

        return null;
    }

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

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