Class MenuSimulator
Base class for components related to menu simulation.
Inherited Members
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
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
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, |
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 |
|
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 |
|