Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Press Tab Using InputTestFixture Not Working

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

  1. Kalita2127

    Kalita2127

    Joined:
    Dec 6, 2014
    Posts:
    279
    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. Kalita2127

    Kalita2127

    Joined:
    Dec 6, 2014
    Posts:
    279
    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