### Example: Using PopupMenuSimulator for Dropdown Interaction Source: https://docs.unity3d.com/Packages/com.unity.ui.test-framework%406.3/manual/simulate/simulate-popup-menu-actions.html This example demonstrates how to add a PopupMenuSimulator, interact with a DropdownField, validate menu display and content, select items by name or index, and discard the menu. It requires setting up the test component and fetching the relevant UI elements. ```csharp public class PopupMenuSimulatorExampleClass : UITestFixture { PopupMenuSimulator m_PopupMenuSimulator; [OneTimeSetUp] public void OneTimeSetUp() { // Add the test component and keep its reference // to interact with popup menus later. m_PopupMenuSimulator = AddTestComponent(); } [Test] public void PopupMenuSimulatorExample() { // Fetch the DropdownMenu to interact with. DropdownField dropdownField = rootVisualElement.Q("MyDropdownField"); VisualElement dropdown = dropdownField.Q(className: "unity-base-popup-field__input"); Assume.That(dropdownField.value, Is.Null); // Click on the dropdown. simulate.Click(dropdown); simulate.FrameUpdate(); // Check that the menu is displayed. Assert.That(m_PopupMenuSimulator.menuIsDisplayed, Is.True, "PopupMenu was not displayed."); // Check that the menu contains the item we want to select. m_PopupMenuSimulator.AssertContainsAction("Option1"); // Select Option1 by its name. m_PopupMenuSimulator.SimulateMenuSelection("Option1"); Assert.That(dropdownField.value, Is.EqualTo("Option1")); // Discard the menu. // PopupMenuSimulator does not currently automatically discard the menu, // so it needs to be manually discarded before opening another menu. m_PopupMenuSimulator.DiscardMenu(); // Click on the dropdown again. simulate.Click(dropdown); simulate.FrameUpdate(); Assert.That(m_PopupMenuSimulator.menuIsDisplayed, Is.True, "PopupMenu was not displayed."); m_PopupMenuSimulator.AssertContainsAction("Option2"); // Simulate item selection by its index. var itemIndex = m_PopupMenuSimulator.FindActionIndex("Option2"); m_PopupMenuSimulator.SimulateItemSelection(itemIndex); Assert.That(dropdownField.value, Is.EqualTo("Option2")); } [SetUp] public void SetUp() { VisualTreeAsset uxml = Resources.Load("UITestFrameworkDocSample"); uxml.CloneTree(rootVisualElement); simulate.FrameUpdate(); } } ``` -------------------------------- ### FixtureSetUp Declaration Source: https://docs.unity3d.com/Packages/com.unity.ui.test-framework%406.3/api/UnityEngine.UIElements.TestFramework.AbstractUITestFixture.html Abstract method for setting up the test fixture. Marked with the SetUp attribute. ```csharp [SetUp] public abstract void FixtureSetUp() ``` -------------------------------- ### Simulate Double-Click on a Button Source: https://docs.unity3d.com/Packages/com.unity.ui.test-framework%406.3/manual/simulate/double-click-on-a-visual-element.html This example demonstrates how to simulate a double-click on a button using PanelSimulator.DoubleClick. It includes setup for a callback to validate the double-click action and asserts the expected behavior. ```csharp using NUnit.Framework; using UnityEngine.UIElements; [Test] public void DoubleClickExample() { // Make sure the UI is totally up to date. simulate.FrameUpdate(); var actionWasExecuted = false; void ValidateDoubleClickAction(PointerDownEvent e) { if (e.clickCount == 2) { actionWasExecuted = true; } } // Set up the button's double click functionality to flip a boolean. Button button = rootVisualElement.Q