Hey all, I’m trying to create a method that simulates keyboard entry for the purpose of automation. I’m using the Unity Platformer Microgame for this task, and there’s basically 3 interactions; jump, move left and move right in this 2D Platformer. The PlayerController.cs class inherits the KinematicObject class, and uses InputAction
In my tests, I’m loading a custom scene, and able to assign the Player to a GameObject; and attempting to add this custom SimulateKeyPress function to the PlayerController.cs file (this is all available in the content); calling it with the key intended and the length of time it should be held down. Is there a way to do this for a consitent timing across multiple platforms, without using a direct TimeSpan or similar element?
[UnityTest]
public IEnumerator GetPlayerAndTokenData()
{
myPlayer = GameObject.Find("Player");
myPlayerController = myPlayer.GetComponent<PlayerController>();
myPlayerController.SimulateKeyPress("spacebar", TimeSpan.FromSeconds(2));
myPlayerController.SimulateKeyPress("a", TimeSpan.FromMilliseconds(500));
yield return null;
}
And below is a glimpse of what I’m trying to write.