Vladyslav Babych
Vladyslav Babych

Reputation: 123

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 hierarchy

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!

Upvotes: 1

Views: 1091

Answers (1)

stamhaney
stamhaney

Reputation: 1312

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;
    }

Upvotes: 2

Related Questions