简体   繁体   中英

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. The menu which shows-up after right-clicking some item, for some reason appears to be outside the main application window in UI Hierarchy:

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

Is there a better way to solve this in 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

        PopUpMenu pop = GetCurrentPopUpMenu();

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

//The GetCurrentPopUpMenu function

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

        return null;
    }

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