Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question Press Tab Using InputTestFixture Not Working

Discussion in 'Testing & Automation' started by Ali_Akbar_Montazeri, Jan 19, 2023.

  1. Ali_Akbar_Montazeri

    Ali_Akbar_Montazeri

    Joined:
    Dec 6, 2014
    Posts:
    221
    So I want to test if the UI is showing by pressing Tab key with virtual input using InputTestFixture.
    Code (CSharp):
    1.  
    2.             _input.Press(Keyboard.current.tabKey);
    3.             InputSystem.Update();
    4.             yield return new WaitForSeconds(UtilTestMethods.FAST_TEST_DURATION);
    5.  
    6.             Assert.IsTrue(menuBar.gameObject.activeInHierarchy);
    7.             Assert.IsTrue(ctrlIInfo.gameObject.activeInHierarchy);
    8.             Assert.IsTrue(voiceAndEmoji.gameObject.activeInHierarchy);
    Quite simple but I have no idea why it failed to show them. Any idea to fix it?
     
  2. noeddie

    noeddie

    Joined:
    Jul 15, 2017
    Posts:
    3
    Hey @Ali_Akbar_Montazeri ,

    The only unusual thing that I noticed was the
    Keyboard.current
    . Are you adding this device somewhere in your test?

    Also, do you have any Player Input component in your scenario?

    Example for this test:

    Code (CSharp):
    1. namespace TestSuite.Features
    2. {
    3.     public class MenuTest : InputTestFixture
    4.     {
    5.         private Keyboard _keyboardDevice;
    6.  
    7.         public override void Setup()
    8.         {
    9.             base.Setup();
    10.  
    11.             _keyboardDevice = InputSystem.AddDevice<Keyboard>();
    12.        
    13.                    UnityEditor.SceneManagement.EditorSceneManager.LoadSceneInPlayMode("Assets/Tests/Features/MenuTest.unity", new LoadSceneParameters(LoadSceneMode.Single));
    14.         }
    15.  
    16.         public override void TearDown()
    17.         {
    18.             GameObject.Find("Player").GetComponent<PlayerInput>().enabled = false;
    19.  
    20.             base.TearDown();
    21.         }
    22.  
    23.         [UnityTest]
    24.         public IEnumerator OpenMenuTest()
    25.         {
    26.             // The "Menu" is a simple empty game object inactive in the test scene by default (first image)
    27.             Assert.That(GameObject.Find("Menu"), Is.EqualTo(null));
    28.  
    29.             Press(_keyboardDevice.tabKey);
    30.  
    31.             yield return null;
    32.  
    33.             Assert.That(GameObject.Find("Menu").activeInHierarchy, Is.EqualTo(true));
    34.         }
    35.  
    36.     }
    37. }


    NOTE: The Player object in this scene has a Player Input component to handle all input events.



     
    Last edited: Jan 27, 2023
  3. Ali_Akbar_Montazeri

    Ali_Akbar_Montazeri

    Joined:
    Dec 6, 2014
    Posts:
    221
    Hi and sorry for the very late response. Actually it's just the Tab key. Alphabet keys like "a" "b" "c" is just fine. So it's not because the
    Keyboard.current
    imo