docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class MenuSimulator

    Base class for components related to menu simulation.

    Inheritance
    object
    UITestComponent
    MenuSimulator
    ContextMenuSimulator
    PopupMenuSimulator
    Inherited Members
    UITestComponent.fixture
    UITestComponent.Initialize(AbstractUITestFixture)
    UITestComponent.Shutdown()
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.UIElements.TestFramework
    Assembly: Unity.UI.TestFramework.Runtime.dll
    Syntax
    public abstract class MenuSimulator : UITestComponent

    Properties

    menuIsDisplayed

    Whether the context menu was displayed.

    Declaration
    public bool menuIsDisplayed { get; }
    Property Value
    Type Description
    bool

    menuItemCount

    The number of items currently in the displayed context menu. Returns 0 if no menu is displayed.

    Declaration
    public int menuItemCount { get; }
    Property Value
    Type Description
    int

    Methods

    AfterTest()

    This function will be invoked when the RemoveTestComponent(UITestComponent) function is called.

    Declaration
    protected override void AfterTest()
    Overrides
    UITestComponent.AfterTest()

    AssertContainsAction(string)

    Asserts that the context menu contains an action with the specified name.

    Declaration
    public void AssertContainsAction(string name)
    Parameters
    Type Name Description
    string name

    The name of the action to check for.

    Exceptions
    Type Condition
    AssertionException

    Thrown if the action is not found in the menu.

    AssertContainsAction(string, Status)

    Asserts that the context menu contains an action with the specified name and expectedStatus.

    Declaration
    public void AssertContainsAction(string name, DropdownMenuAction.Status expectedStatus)
    Parameters
    Type Name Description
    string name

    The name of the action to check for.

    DropdownMenuAction.Status expectedStatus

    The expected status of the action.

    Exceptions
    Type Condition
    AssertionException

    Thrown if the action is not found or its status does not match the expected value.

    BeforeTest()

    This function will be invoked when the AddTestComponent(UITestComponent) function is called.

    Declaration
    protected override void BeforeTest()
    Overrides
    UITestComponent.BeforeTest()

    DiscardMenu()

    Resets relevant MenuSimulator properties. Resets the menu state, hides the menu, and clears any menu data.

    Declaration
    public virtual void DiscardMenu()

    FindActionIndex(string)

    Finds the index of a menu action by its name.

    Declaration
    public int FindActionIndex(string name)
    Parameters
    Type Name Description
    string name

    The name of the menu action to find.

    Returns
    Type Description
    int

    The zero-based index of the action if found and the menu is displayed; otherwise, -1.

    SimulateItemSelection(int)

    Simulates the selection of a menu item by index. Executes the associated action if the menu is displayed, the itemIndex is valid and the action is not disabled.

    Declaration
    public bool SimulateItemSelection(int itemIndex)
    Parameters
    Type Name Description
    int itemIndex

    The zero-based index of the menu item to select.

    Returns
    Type Description
    bool

    True if the action was executed; false otherwise.

    SimulateMenuSelection(string)

    Simulates the selection of a menu item by its action name. Executes the associated action if found and the action is not disabled.

    Declaration
    public bool SimulateMenuSelection(string name)
    Parameters
    Type Name Description
    string name

    The name of the menu action to select.

    Returns
    Type Description
    bool

    True if the action was executed; false otherwise.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)