API

AltUnityDriver

The AltUnityDriver class represents the main game driver component. When you instantiate an AltUnityDriver in your tests, you can use it to “drive” your game like one of your users would, by interacting with all the game objects, their properties and methods. An AltUnityDriver instance will connect to the AltUnity Proxy that bridges the connection with the instrumented Unity application. In the constructor, we need to tell the driver where (on what IP and on what port) the proxy is running. We can also set some more advanced parameters, as shown in the table below:

Parameters

Name Type Required Description
host string No The ip or hostname AltUnity Proxy is listening on. The default value for this is "127.0.0.1"
port int No The default value for this is 13000
enableLogging boolean No If true, enables logging on the driver. The default value for this is false
connectTimeout int No Number of seconds to retry connection to proxy. The default value for this is 60 seconds

Once you have an instance of the AltUnityDriver, you can use all the available commands to interact with the game. The available methods are the following:

Find Objects

FindObject

Finds the first object in the scene that respects the given criteria. Check By for more information about criterias.

Parameters

Name Type Required Description
by By Yes Set what criteria to use in order to find the object
value string Yes The value to which object will be compared to see if they respect the criteria or not
cameraBy By No Set what criteria to use in order to find the camera
cameraValue string No The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene.
enabled boolean No If true will match only objects that are active in hierarchy. If false will match all objects.

Returns

  • AltUnityObject

Examples

[Test]
public void TestFindAltUnityObject()
{
    const string name = "Capsule";
    var altUnityObject = altUnityDriver.FindObject(By.NAME,name);
    Assert.NotNull(altUnityObject);
    Assert.AreEqual(name, altUnityObject.name);
}

FindObjects

Finds all objects in the scene that respects the given criteria. Check By for more information about criterias.

Parameters

Name Type Required Description
by By Yes Set what criteria to use in order to find the object
value string Yes The value to which object will be compared to see if they respect the criteria or not
cameraBy By No Set what criteria to use in order to find the camera
cameraValue string No The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene.
enabled boolean No If true will match only objects that are active in hierarchy. If false will match all objects.

Returns

  • List of AltUnityObjects/ empty list if no objects were found

Examples

[Test]
public void TestFindObjectsByTag()
{
    var altUnityObjects = altUnityDriver.FindObjects(By.TAG,"plane");
    Assert.AreEqual(2, altUnityObjects.Count);
    foreach(var altUnityObject in altUnityObjects)
    {
        Assert.AreEqual("Plane", altUnityObject.name);
    }
}

FindObjectWhichContains

Finds the first object in the scene that respects the given criteria. Check By for more information about criterias.

Parameters

Name Type Required Description
by By Yes Set what criteria to use in order to find the object
value string Yes The value to which object will be compared to see if they respect the criteria or not
cameraBy By No Set what criteria to use in order to find the camera
cameraValue string No The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene.
enabled boolean No If true will match only objects that are active in hierarchy. If false will match all objects.

Returns

  • AltUnityObjects

Examples

[Test]
 public void TestFindObjectWhichContains()
 {
     var altUnityObject = altUnityDriver.FindObjectWhichContains(By.NAME, "Event");
     Assert.AreEqual("EventSystem", altUnityObject.name);
 }

FindObjectsWhichContain

Finds all objects in the scene that respects the given criteria. Check By for more information about criterias.

Parameters

Name Type Required Description
by By Yes Set what criteria to use in order to find the object
value string Yes The value to which object will be compared to see if they respect the criteria or not
cameraBy By No Set what criteria to use in order to find the camera
cameraValue string No The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene.
enabled boolean No If true will match only objects that are active in hierarchy. If false will match all objects.

Returns

  • List of AltUnityObjects/ empty list if no objects were found

Examples

[Test]
public void TestFindObjectWhichContains()
{
  var altUnityObject = altUnityDriver.FindObjectWhichContain(By.NAME, "Event");
  Assert.AreEqual("EventSystem", altUnityObject.name);
}

GetAllElements

Returns information about every objects loaded in the currently loaded scenes. This also means objects that are set as DontDestroyOnLoad.

Parameters

Name Type Required Description
cameraBy By No Set what criteria to use in order to find the camera
cameraValue string No The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene.
enabled boolean No If true will match only objects that are active in hierarchy. If false will match all objects.

Returns

  • List of AltUnityObjects/ empty list if no objects were found

Examples

[Test]
public void TestGetAllEnabledObjects()
{

    var altUnityObjects = altUnityDriver.GetAllElements(enabled: true);
    Assert.IsNotEmpty(altUnityObjects);
    string listOfObjects="";
        foreach(var object in altUnityObjects){
        listOfObjects=object.name+"; ";
    }
    Debug.Log(listOfObjects);
    Assert.AreEqual(19, altUnityObjects.Count);
    Assert.IsNotNull(altUnityObjects.Where(p => p.name == "Capsule"));
    Assert.IsNotNull(altUnityObjects.Where(p => p.name == "Main Camera"));
    Assert.IsNotNull(altUnityObjects.Where(p => p.name == "Directional Light"));
    Assert.IsNotNull(altUnityObjects.Where(p => p.name == "Plane"));
    Assert.IsNotNull(altUnityObjects.Where(p => p.name == "Canvas"));
    Assert.IsNotNull(altUnityObjects.Where(p => p.name == "EventSystem"));
    Assert.IsNotNull(altUnityObjects.Where(p => p.name == "AltUnityRunner"));
    Assert.IsNotNull(altUnityObjects.Where(p => p.name == "CapsuleInfo"));
    Assert.IsNotNull(altUnityObjects.Where(p => p.name == "UIButton"));
    Assert.IsNotNull(altUnityObjects.Where(p => p.name == "Text"));
}

WaitForObject

Waits until it finds an object that respects the given criteria or until timeout limit is reached. Check By for more information about criterias.

Parameters

Name Type Required Description
by By Yes Set what criteria to use in order to find the object
value string Yes The value to which object will be compared to see if they respect the criteria or not
cameraBy By No Set what criteria to use in order to find the camera
cameraValue string No The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene.
enabled boolean No If true will match only objects that are active in hierarchy. If false will match all objects.
timeout double No number of seconds that it will wait for object
interval double No number of seconds after which it will try to find the object again. interval should be smaller than timeout

Returns

  • AltUnityObject

Examples

[Test]
 public void TestWaitForObjectToNotExistFail()
 {
     try
     {
         altUnityDriver.WaitForObjectNotBePresent(By.NAME,"Capsule", timeout: 1, interval: 0.5f);
         Assert.Fail();
     }
     catch (WaitTimeOutException exception)
     {
         Assert.AreEqual("Element //Capsule still found after 1 seconds", exception.Message);
     }
 }

WaitForObjectWhichContains

Waits until it finds an object that respects the given criteria or time runs out and will throw an error. Check By for more information about criterias.

Parameters

Name Type Required Description
by By Yes Set what criteria to use in order to find the object
value string Yes The value to which object will be compared to see if they respect the criteria or not
cameraBy By No Set what criteria to use in order to find the camera
cameraValue string No The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene.
enabled boolean No If true will match only objects that are active in hierarchy. If false will match all objects.
timeout double No number of seconds that it will wait for object
interval double No number of seconds after which it will try to find the object again. interval should be smaller than timeout

Returns

  • AltUnityObject

Examples

[Test]
public void TestWaitForObjectWhichContains()
{
    var altUnityObject = altUnityDriver.WaitForObjectWhichContains(By.NAME, "Canva");
    Assert.AreEqual("Canvas", altUnityObject.name);
}

WaitForObjectNotBePresent

Waits until the object in the scene that respects the given criteria is no longer in the scene or until timeout limit is reached. Check By for more information about criterias.

Parameters

Name Type Required Description
by By Yes Set what criteria to use in order to find the object
value string Yes The value to which object will be compared to see if they respect the criteria or not
cameraBy By No Set what criteria to use in order to find the camera
cameraValue string No The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene.
enabled boolean No If true will match only objects that are active in hierarchy. If false will match all objects.
timeout double No number of seconds that it will wait for object
interval double No number of seconds after which it will try to find the object again. interval should be smaller than timeout

Returns

  • Nothing

Examples

[Test]
public void TestWaitForObjectToNotExist()
{
    altUnityDriver.WaitForObjectNotBePresent(By.NAME, "Capsulee", timeout: 1, interval: 0.5f);
}

Input Actions

MoveMouseAndWait

Simulates mouse movement in your game. This command will wait for the movement to finish. If you don’t want to wait until the mouse movement stops use MoveMouse

Parameters

Name Type Required Description
location AltUnityVector2 Yes The destination coordinates for mouse to go from the current mouse position
duration float Yes The time measured in seconds to move the mouse from current position to the set location.

Returns

  • Nothing

Examples

[Test]
public void TestCreatingStars()
{
    altUnityDriver.LoadScene("Scene 5 Keyboard Input");

    var stars = altUnityDriver.FindObjectsWhichContain(By.NAME, "Star","Player2");
    var player = altUnityDriver.FindObjectsWhichContain(By.NAME, "Player", "Player2");
    Assert.AreEqual(1, stars.Count);

    altUnityDriver.MoveMouse(new AltUnityVector2(player[0].x, player[0].y+500), 1);
    UnityEngine.Debug.Log(stars[0].x+"  "+stars[0].y);
    Thread.Sleep(1500);

    altUnityDriver.PressKey(AltUnityKeyCode.KeyCode.Mouse0, 0);
    altUnityDriver.MoveMouseAndWait(new AltUnityVector2(player[0].x, player[0].y-500), 1);
    Thread.Sleep(1500);
    altUnityDriver.PressKeyAndWait(AltUnityKeyCode.KeyCode.Mouse0, 1);

    stars = altUnityDriver.FindObjectsWhichContain(By.NAME,"Star");
    Assert.AreEqual(3, stars.Count);
}

KeyDown

Simulates that a specific key was pressed without taking into consideration the duration of the press.

Parameters

Name Type Required Description
keyCode AltUnityKeyCode Yes The keyCode of the key simulated to be pressed.
power int Yes A value between [-1,1] used for joysticks to indicate how hard the button was pressed.

Returns

  • Nothing

Examples

[Test]
public void TestKeyDownAndKeyUp()
{
    altUnityDriver.LoadScene("Scene 5 Keyboard Input");
    AltUnityKeyCode kcode = AltUnityKeyCode.A;

    altUnityDriver.KeyDown(kcode, 1);
    var lastKeyDown = altUnityDriver.FindObject(By.NAME, "LastKeyDownValue");
    var lastKeyPress = altUnityDriver.FindObject(By.NAME, "LastKeyPressedValue");

    Assert.AreEqual((int)kcode, (int)Enum.Parse(typeof(AltUnityKeyCode), lastKeyDown.GetText(), true));
    Assert.AreEqual((int)kcode, (int)Enum.Parse(typeof(AltUnityKeyCode), lastKeyPress.GetText(), true));

    altUnityDriver.KeyUp(kcode);
    var lastKeyUp = altUnityDriver.FindObject(By.NAME, "LastKeyUpValue");

    Assert.AreEqual((int)kcode, (int)Enum.Parse(typeof(AltUnityKeyCode), lastKeyUp.GetText(), true));
}

KeyUp

Simulates that a specific key was released.

Parameters

Name Type Required Description
keyCode AltUnityKeyCode Yes The keyCode of the key simulated to be released.

Returns

  • Nothing

Examples

[Test]
public void TestKeyDownAndKeyUp()
{
    altUnityDriver.LoadScene("Scene 5 Keyboard Input");
    AltUnityKeyCode kcode = AltUnityKeyCode.A;

    altUnityDriver.KeyDown(kcode, 1);
    var lastKeyDown = altUnityDriver.FindObject(By.NAME, "LastKeyDownValue");
    var lastKeyPress = altUnityDriver.FindObject(By.NAME, "LastKeyPressedValue");

    Assert.AreEqual((int)kcode, (int)Enum.Parse(typeof(AltUnityKeyCode), lastKeyDown.GetText(), true));
    Assert.AreEqual((int)kcode, (int)Enum.Parse(typeof(AltUnityKeyCode), lastKeyPress.GetText(), true));

    altUnityDriver.KeyUp(kcode);
    var lastKeyUp = altUnityDriver.FindObject(By.NAME, "LastKeyUpValue");

    Assert.AreEqual((int)kcode, (int)Enum.Parse(typeof(AltUnityKeyCode), lastKeyUp.GetText(), true));
}

HoldButton

Simulates holding left click button down for a specified amount of time at given coordinates. This command does not wait for the button press to finish. To wait for button press to finish use HoldButtonAndWait.

Parameters

Name Type Required Description
position AltUnityVector2 Yes The coordinates where the button is held down.
duration float Yes The time measured in seconds to keep the button down.

Returns

  • Nothing

Examples

[Test]
public void TestHoldButton()
{
    var button = altUnityDriver.FindObject(By.NAME, "UIButton");
    AltUnityVector2 vector2 = new AltUnityVector2(button.x, button.y);
    altUnityDriver.HoldButton(vector2, 1);
    Thread.Sleep(1400);
    var capsuleInfo = altUnityDriver.FindObject(By.NAME, "CapsuleInfo");
    Thread.Sleep(1400);
    var text = capsuleInfo.GetText();
    Assert.AreEqual(text, "UIButton clicked to jump capsule!");
}

HoldButtonAndWait

Simulates holding left click button down for a specified amount of time at given coordinates and waits for the button press to finish. If you don’t want to wait until the command finishes use HoldButton.

Parameters

Name Type Required Description
position AltUnityVector2 Yes The coordinates where the button is held down.
duration float Yes The time measured in seconds to keep the button down.

Returns

  • Nothing

Examples

[Test]
public void TestHoldButton()
{
    var button = altUnityDriver.FindObject(By.NAME, "UIButton");
    AltUnityVector2 vector2 = new AltUnityVector2(button.x, button.y);
    altUnityDriver.HoldButtonAndWait(vector2, 1);
    var capsuleInfo = altUnityDriver.FindObject(By.NAME, "CapsuleInfo");
    Thread.Sleep(1400);
    var text = capsuleInfo.GetText();
    Assert.AreEqual(text, "UIButton clicked to jump capsule!");
}

MoveMouse

Simulates mouse movement in your game. This command does not wait for the movement to finish. To also wait for the movement to finish use MoveMouseAndWait

Parameters

Name Type Required Description
location AltUnityVector2 Yes The destination coordinates for mouse to go from the current mouse position
duration float Yes The time measured in seconds to move the mouse from current position to the set location.

Returns

  • Nothing

Examples

[Test]
public void TestCreatingStars()
{
    altUnityDriver.LoadScene("Scene 5 Keyboard Input");

    var stars = altUnityDriver.FindObjectsWhichContain(By.NAME, "Star","Player2");
    var player = altUnityDriver.FindObjectsWhichContain(By.NAME, "Player", "Player2");
    Assert.AreEqual(1, stars.Count);

    altUnityDriver.MoveMouse(new AltUnityVector2(player[0].x, player[0].y+500), 1);
    UnityEngine.Debug.Log(stars[0].x+"  "+stars[0].y);
    Thread.Sleep(1500);

    altUnityDriver.PressKey(AltUnityKeyCode.KeyCode.Mouse0, 0);
    altUnityDriver.MoveMouseAndWait(new AltUnityVector2(player[0].x, player[0].y-500), 1);
    Thread.Sleep(1500);
    altUnityDriver.PressKeyAndWait(AltUnityKeyCode.KeyCode.Mouse0, 1);

    stars = altUnityDriver.FindObjectsWhichContain(By.NAME,"Star");
    Assert.AreEqual(3, stars.Count);
}

PressKeyAndWait

Simulates key press action in your game. This command waits for the action to finish. If you don’t want to wait the action to finish use PressKey

Parameters

Name Type Required Description
keycode AltUnityKeyCode Yes Name of the button.
power float Yes A value from [-1,1] that defines how strong the key was pressed. This is mostly used for joystick button since the keyboard button will always be 1 or -1.
duration float Yes The time measured in seconds from the key press to the key release.

Returns

  • Nothing

Examples

[Test]
public void TestCreatingStars()
{
    altUnityDriver.LoadScene("Scene 5 Keyboard Input");

    var stars = altUnityDriver.FindObjectsWhichContain(By.NAME, "Star","Player2");
    var player = altUnityDriver.FindObjectsWhichContain(By.NAME, "Player", "Player2");
    Assert.AreEqual(1, stars.Count);

    altUnityDriver.MoveMouse(new AltUnityVector2(player[0].x, player[0].y+500), 1);
    UnityEngine.Debug.Log(stars[0].x+"  "+stars[0].y);
    Thread.Sleep(1500);

    altUnityDriver.PressKey(AltUnityKeyCode.KeyCode.Mouse0, 0);
    altUnityDriver.MoveMouseAndWait(new AltUnityVector2(player[0].x, player[0].y-500), 1);
    Thread.Sleep(1500);
    altUnityDriver.PressKeyAndWait(AltUnityKeyCode.KeyCode.Mouse0, 1);

    stars = altUnityDriver.FindObjectsWhichContain(By.NAME,"Star");
    Assert.AreEqual(3, stars.Count);
}

PressKey

Simulates key press action in your game. This command does not wait for the action to finish. To also wait for the action to finish use PressKeyAndWait

Parameters

Name Type Required Description
keycode AltUnityKeyCode Yes Name of the button.
power float Yes A value from [-1,1] that defines how strong the key was pressed. This is mostly used for joystick button since the keyboard button will always be 1 or -1
duration float Yes The time measured in seconds from the key press to the key release.

Returns

  • Nothing

Examples

[Test]
public void TestCreatingStars()
{
    altUnityDriver.LoadScene("Scene 5 Keyboard Input");

    var stars = altUnityDriver.FindObjectsWhichContain(By.NAME, "Star","Player2");
    var player = altUnityDriver.FindObjectsWhichContain(By.NAME, "Player", "Player2");
    Assert.AreEqual(1, stars.Count);

    altUnityDriver.MoveMouse(new AltUnityVector2(player[0].x, player[0].y+500), 1);
    UnityEngine.Debug.Log(stars[0].x+"  "+stars[0].y);
    Thread.Sleep(1500);

    altUnityDriver.PressKey(AltUnityKeyCode.KeyCode.Mouse0, 0);
    altUnityDriver.MoveMouseAndWait(new AltUnityVector2(player[0].x, player[0].y-500), 1);
    Thread.Sleep(1500);
    altUnityDriver.PressKeyAndWait(AltUnityKeyCode.KeyCode.Mouse0, 1);

    stars = altUnityDriver.FindObjectsWhichContain(By.NAME,"Star");
    Assert.AreEqual(3, stars.Count);
}

ScrollMouseAndWait

Simulates scroll mouse action in your game. This command waits for the action to finish. If you don’t want to wait until the action to finish use ScrollMouse

Parameters

Name Type Required Description
speed float Yes Set how fast to scroll. Positive values will scroll up and negative values will scroll down.
duration float Yes The time measured in seconds to scroll.

Returns

  • Nothing

Examples

[Test]
public void TestScrollAndWait()
{

    altUnityDriver.LoadScene("Scene 5 Keyboard Input");
    var player2 = altUnityDriver.FindObject(By.NAME, "Player2");
    AltUnityVector3 cubeInitialPostion = new AltUnityVector3(player2.worldX, player2.worldY, player2.worldY);
    altUnityDriver.ScrollMouseAndWait(4, 2);
    player2 = altUnityDriver.FindObject(By.NAME, "Player2");
    AltUnityVector3 cubeFinalPosition = new AltUnityVector3(player2.worldX, player2.worldY, player2.worldY);

    Assert.AreNotEqual(cubeInitialPostion, cubeFinalPosition);
}

ScrollMouse

Simulates scroll mouse action in your game. This command does not wait for the action to finish. To also wait for the action to finish use ScrollMouseAndWait

Parameters

Name Type Required Description
speed float Yes Set how fast to scroll. Positive values will scroll up and negative values will scroll down.
duration float Yes The time measured in seconds to scroll.

Returns

  • Nothing

Examples

[Test]
public void TestScroll()
{

    altUnityDriver.LoadScene("Scene 5 Keyboard Input");
    var player2 = altUnityDriver.FindObject(By.NAME, "Player2");
    AltUnityVector3 cubeInitialPostion = new AltUnityVector3(player2.worldX, player2.worldY, player2.worldY);
    altUnityDriver.ScrollMouse(4,2);
    Thread.Sleep(2000);
    player2 = altUnityDriver.FindObject(By.NAME, "Player2");
    AltUnityVector3 cubeFinalPosition = new AltUnityVector3(player2.worldX, player2.worldY, player2.worldY);
    Assert.AreNotEqual(cubeInitialPostion, cubeFinalPosition);
}

SwipeAndWait

Simulates a swipe action in your game. This command waits for the action to finish. If you don’t want to wait until the action to finish use Swipe

Parameters

Name Type Required Description
start AltUnityVector2(C#) Yes Starting location of the swipe
end AltUnityVector2(C#) Yes Ending location of the swipe
xStart float(python/java) Yes x coordinate of the screen where the swipe begins.
yStart float(python/java) Yes y coordinate of the screen where the swipe begins
xEnd float(python/java) Yes x coordinate of the screen where the swipe ends
yEnd float(python/java) Yes x coordinate of the screen where the swipe ends
duration float Yes The time measured in seconds to move the mouse from current position to the set location.

Returns

  • Nothing

Examples

[Test]
public void MultipleDragAndDropWait()
{
    var altUnityObject1 = altUnityDriver.FindObject(By.NAME,"Drag Image1");
    var altUnityObject2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    altUnityDriver.SwipeAndWait(new AltUnityVector2(altUnityObject1.x, altUnityObject1.y), new AltUnityVector2(altUnityObject2.x, altUnityObject2.y), 1);

    altUnityObject1 = altUnityDriver.FindObject(By.NAME,"Drag Image2");
    altUnityObject2 = altUnityDriver.FindObject(By.NAME,"Drop Box2");
    altUnityDriver.SwipeAndWait(new AltUnityVector2(altUnityObject1.x, altUnityObject1.y), new AltUnityVector2(altUnityObject2.x, altUnityObject2.y), 1);

    altUnityObject1 = altUnityDriver.FindObject(By.NAME,"Drag Image3");
    altUnityObject2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    altUnityDriver.SwipeAndWait(new AltUnityVector2(altUnityObject1.x, altUnityObject1.y), new AltUnityVector2(altUnityObject2.x, altUnityObject2.y), 1);

    altUnityObject1 = altUnityDriver.FindObject(By.NAME,"Drag Image1");
    altUnityObject2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    altUnityDriver.SwipeAndWait(new AltUnityVector2(altUnityObject1.x, altUnityObject1.y), new AltUnityVector2(altUnityObject2.x, altUnityObject2.y), 1);
    var imageSource = altUnityDriver.FindObject(By.NAME,"Drag Image1").GetComponentProperty("UnityEngine.UI.Image", "sprite");
    var imageSourceDropZone = altUnityDriver.FindObject(By.NAME,"Drop Image").GetComponentProperty("UnityEngine.UI.Image", "sprite");
    Assert.AreNotEqual(imageSource, imageSourceDropZone);

    imageSource = altUnityDriver.FindObject(By.NAME,"Drag Image2").GetComponentProperty("UnityEngine.UI.Image", "sprite");
    imageSourceDropZone = altUnityDriver.FindObject(By.NAME,"Drop").GetComponentProperty("UnityEngine.UI.Image", "sprite");
    Assert.AreNotEqual(imageSource, imageSourceDropZone);

}

Swipe

Simulates a swipe action in your game. This command does not wait for the action to finish. To also wait for the action to finish use SwipeAndWait

Parameters

Name Type Required Description
start AltUnityVector2(C#) Yes Starting location of the swipe
end AltUnityVector2(C#) Yes Ending location of the swipe
xStart float(python/java) Yes x coordinate of the screen where the swipe begins.
yStart float(python/java) Yes y coordinate of the screen where the swipe begins
xEnd float(python/java) Yes x coordinate of the screen where the swipe ends
yEnd float(python/java) Yes x coordinate of the screen where the swipe ends
duration float Yes The time measured in seconds to move the mouse from current position to the set location.

Returns

  • Nothing

Examples

[Test]
public void MultipleDragAndDrop()
{
    var altUnityObject1 = altUnityDriver.FindObject(By.NAME,"Drag Image1");
    var altUnityObject2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    altUnityDriver.Swipe(new AltUnityVector2(altUnityObject1.x, altUnityObject1.y), new AltUnityVector2(altUnityObject2.x, altUnityObject2.y), 1);

    altUnityObject1 = altUnityDriver.FindObject(By.NAME,"Drag Image2");
    altUnityObject2 = altUnityDriver.FindObject(By.NAME,"Drop Box2");
    altUnityDriver.Swipe(new AltUnityVector2(altUnityObject1.x, altUnityObject1.y), new AltUnityVector2(altUnityObject2.x, altUnityObject2.y), 2);

    altUnityObject1 = altUnityDriver.FindObject(By.NAME,"Drag Image3");
    altUnityObject2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    altUnityDriver.Swipe(new AltUnityVector2(altUnityObject1.x, altUnityObject1.y), new AltUnityVector2(altUnityObject2.x, altUnityObject2.y), 2);

    altUnityObject1 = altUnityDriver.FindObject(By.NAME,"Drag Image1");
    altUnityObject2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    altUnityDriver.Swipe(new AltUnityVector2(altUnityObject1.x, altUnityObject1.y), new AltUnityVector2(altUnityObject2.x, altUnityObject2.y), 3);

    Thread.Sleep(4000);

    var imageSource = altUnityDriver.FindObject(By.NAME,"Drag Image1").GetComponentProperty("UnityEngine.UI.Image", "sprite");
    var imageSourceDropZone= altUnityDriver.FindObject(By.NAME,"Drop Image").GetComponentProperty("UnityEngine.UI.Image", "sprite");
    Assert.AreNotEqual(imageSource, imageSourceDropZone);

     imageSource = altUnityDriver.FindObject(By.NAME,"Drag Image2").GetComponentProperty("UnityEngine.UI.Image", "sprite");
     imageSourceDropZone = altUnityDriver.FindObject(By.NAME,"Drop").GetComponentProperty("UnityEngine.UI.Image", "sprite");
    Assert.AreNotEqual(imageSource, imageSourceDropZone);

}

MultiPointSwipe

Similar command like swipe but instead of swipe from point A to point B you are able to give list a points.

Parameters

Name Type Required Description
positions List/Array of AltUnityVector2 Yes collection of positions on the screen where the swipe be made
duration float Yes how many seconds the swipe will need to complete

Returns

  • Nothing

Examples

[Test]
public void ResizePanelWithMultipointSwipe()
{
    var altUnityObject = altUnityDriver.FindObject(By.NAME,"Resize Zone");
    var position = new AltUnityVector2(altUnityObject.x, altUnityObject.y);
    var pos = new []
    {
        altUnityObject.getScreenPosition(),
        new AltUnityVector2(altUnityObject.x - 200, altUnityObject.y - 200),
        new AltUnityVector2(altUnityObject.x - 300, altUnityObject.y - 100),
        new AltUnityVector2(altUnityObject.x - 50, altUnityObject.y - 100),
        new AltUnityVector2(altUnityObject.x - 100, altUnityObject.y - 100)
    };
    altUnityDriver.MultipointSwipe(pos, 4);

    Thread.Sleep(4000);

    altUnityObject = altUnityDriver.FindObject(By.NAME,"Resize Zone");
    var position2 = new AltUnityVector2(altUnityObject.x, altUnityObject.y);
    Assert.AreNotEqual(position, position2);
}

MultiPointSwipeAndWait

Similar command like SwipeAndWait but instead of swipe from point A to point B you are able to give list a points.

Parameters

Name Type Required Description
positions List/Array of AltUnityVector2 Yes collection of positions on the screen where the swipe be made
duration float Yes how many seconds the swipe will need to complete

Returns

  • Nothing

Examples

[Test]
public void MultipleDragAndDropWaitWithMultipointSwipe()
{
    var altUnityObject1 = altUnityDriver.FindObject(By.NAME,"Drag Image1");
    var altUnityObject2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    altUnityDriver.MultipointSwipe(new []{new AltUnityVector2(altUnityObject1.x, altUnityObject1.y), new AltUnityVector2(altUnityObject2.x, altUnityObject2.y)}, 2);
    Thread.Sleep(2000);

    altUnityObject1 = altUnityDriver.FindObject(By.NAME,"Drag Image1");
    altUnityObject2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    var altUnityObject3 = altUnityDriver.FindObject(By.NAME,"Drop Box2");
    var positions = new[]
    {
        new AltUnityVector2(altUnityObject1.x, altUnityObject1.y),
        new AltUnityVector2(altUnityObject2.x, altUnityObject2.y),
        new AltUnityVector2(altUnityObject3.x, altUnityObject3.y)
    };

    altUnityDriver.MultipointSwipeAndWait(positions, 3);
    var imageSource = altUnityDriver.FindObject(By.NAME,"Drag Image1").GetComponentProperty("UnityEngine.UI.Image", "sprite");
    var imageSourceDropZone = altUnityDriver.FindObject(By.NAME,"Drop Image").GetComponentProperty("UnityEngine.UI.Image", "sprite");
    Assert.AreNotEqual(imageSource, imageSourceDropZone);

    imageSource = altUnityDriver.FindObject(By.NAME,"Drag Image2").GetComponentProperty("UnityEngine.UI.Image", "sprite");
    imageSourceDropZone = altUnityDriver.FindObject(By.NAME,"Drop").GetComponentProperty("UnityEngine.UI.Image", "sprite");
    Assert.AreNotEqual(imageSource, imageSourceDropZone);
}

BeginTouch

Simulates starting of a touch on the screen. To further interact with the touch use MoveTouch and EndTouch

Parameters

Name Type Required Description
coordinates AltUnityVector2(C#) Yes Screen coordinates

Returns

  • int fingerId

Examples

[Test]
public void TestNewTouchCommands()
{
    var draggableArea = altUnityDriver.FindObject(By.NAME, "Drag Zone");
    var initialPosition = draggableArea.getScreenPosition();
    int fingerId = altUnityDriver.BeginTouch(draggableArea.getScreenPosition());
    AltUnityVector2 newPosition = new AltUnityVector2(draggableArea.x + 20, draggableArea.y + 10);
    altUnityDriver.MoveTouch(fingerId, newPosition);
    altUnityDriver.EndTouch(fingerId);
    draggableArea = altUnityDriver.FindObject(By.NAME, "Drag Zone");
    Assert.AreNotEqual(initialPosition, draggableArea.getScreenPosition());

}

MoveTouch

Simulates a touch movement on the screen. Move the touch created with BeginTouch from the previous position to the position given as parameters.

Parameters

Name Type Required Description
fingerId int Yes Identifier returned by BeginTouch command
coordinates AltUnityVector2(C#) Yes Screen coordinates where the touch will be moved

Returns

  • void

Examples

[Test]
public void TestNewTouchCommands()
{
    var draggableArea = altUnityDriver.FindObject(By.NAME, "Drag Zone");
    var initialPosition = draggableArea.getScreenPosition();
    int fingerId = altUnityDriver.BeginTouch(draggableArea.getScreenPosition());
    AltUnityVector2 newPosition = new AltUnityVector2(draggableArea.x + 20, draggableArea.y + 10);
    altUnityDriver.MoveTouch(fingerId, newPosition);
    altUnityDriver.EndTouch(fingerId);
    draggableArea = altUnityDriver.FindObject(By.NAME, "Drag Zone");
    Assert.AreNotEqual(initialPosition, draggableArea.getScreenPosition());

}

EndTouch

Simulates ending of a touch on the screen. This command will destroy the touch making it no longer usable to other movements.

Parameters

Name Type Required Description
fingerId int Yes Identifier returned by BeginTouch command

Returns

  • void

Examples

[Test]
public void TestNewTouchCommands()
{
    var draggableArea = altUnityDriver.FindObject(By.NAME, "Drag Zone");
    var initialPosition = draggableArea.getScreenPosition();
    int fingerId = altUnityDriver.BeginTouch(draggableArea.getScreenPosition());
    AltUnityVector2 newPosition = new AltUnityVector2(draggableArea.x + 20, draggableArea.y + 10);
    altUnityDriver.MoveTouch(fingerId, newPosition);
    altUnityDriver.EndTouch(fingerId);
    draggableArea = altUnityDriver.FindObject(By.NAME, "Drag Zone");
    Assert.AreNotEqual(initialPosition, draggableArea.getScreenPosition());

}

Click

Click at screen coordinates

Parameters

Name Type Required Default Description
coordinates AltUnityVector2 Yes The screen coordinates
count int No 1 Number of clicks
interval float No 0.1 Interval between clicks in seconds
wait boolean No true Wait for command to finish

Returns

  • void

Examples

[Test]
public void TestClickCoordinates()
{
    const string name = "UIButton";
    var altUnityObject = altUnityDriver.FindObject(By.NAME,name);
    altUnityDriver.Click(altUnityObject.getScreenPosition());
    Assert.AreEqual(name, altUnityObject.name);
    altUnityDriver.WaitForObject(By.PATH,"//CapsuleInfo[@text="UIButton clicked to jump capsule!"]");
}

Tap

Tap at screen coordinates

Parameters

Name Type Required Default Description
coordinates AltUnityVector2 Yes The screen coordinates
count int No 1 Number of taps
interval float No 0.1 Interval between taps in seconds
wait boolean No true Wait for command to finish

Returns

  • void

Examples

[Test]
public void TestTapCoordinates()
{
    const string name = "UIButton";
    var altUnityObject = altUnityDriver.FindObject(By.NAME,name);
    altUnityDriver.Tap(altUnityObject.getScreenPosition());
    Assert.AreEqual(name, altUnityObject.name);
    altUnityDriver.WaitForObject(By.PATH,"//CapsuleInfo[@text="UIButton clicked to jump capsule!"]");
}

Tilt

Simulates device rotation action in your game.

Parameters

Name Type Required Description
acceleration AltUnityVector3(C#) Yes Linear acceleration of a device in three-dimensional space
x float(python/java) Yes Linear acceleration of a device on x
y float(python/java) Yes Linear acceleration of a device on y
z float(python/java) Yes Linear acceleration of a device on z
duration float Yes How long the rotation will take in seconds

Returns

  • Nothing

Examples

[Test]
public void TestAcceleration()
{
    var capsule= altUnityDriver.FindObject(By.NAME, "Capsule");
    var initialWorldCoordinates = capsule.getWorldPosition();
    altUnityDriver.Tilt(new AltUnityVector3(1, 1, 1),1);
    Thread.Sleep(1000);
    capsule = altUnityDriver.FindObject(By.NAME, "Capsule");
    var afterTiltCoordinates = capsule.getWorldPosition();
    Assert.AreNotEqual(initialWorldCoordinates, afterTiltCoordinates);
}

TiltAndWait

Simulates device rotation action in your game. This command waits for the action to finish. If you don’t want to wait until the action to finish use Tilt

Parameters

Name Type Required Description
acceleration AltUnityVector3(C#) Yes Linear acceleration of a device in three-dimensional space
x float(python/java) Yes Linear acceleration of a device on x
y float(python/java) Yes Linear acceleration of a device on y
z float(python/java) Yes Linear acceleration of a device on z
duration float Yes How long the rotation will take in seconds

Returns

  • Nothing

Examples

[Test]
public void TestAccelerationAndWait()
{
    var capsule = altUnityDriver.FindObject(By.NAME, "Capsule");
    var initialWorldCoordinates = capsule.getWorldPosition();
    altUnityDriver.TiltAndWait(new AltUnityVector3(1, 1, 1), 1);
    Thread.Sleep(1000);
    capsule = altUnityDriver.FindObject(By.NAME, "Capsule");
    var afterTiltCoordinates = capsule.getWorldPosition();
    Assert.AreNotEqual(initialWorldCoordinates, afterTiltCoordinates);
}

Screenshot

GetPNGScreenshot

Creates a screenshot of the current scene in png format.

Parameters

Name Type Required Description
path string Yes location where the image is created

Returns

  • Nothing

Examples

[Test]
public void TestGetScreenshot()
{
    var path="testC.png";
    altUnityDriver.GetPNGScreenshot(path);
    FileAssert.Exists(path);
}

Unity Commands

PlayerPrefKeyType

This is an enum type used for the option parameter in the set_player_pref_key command listed below and has the following values:

Type Assigned Value
Int 1
String 2
Float 3

GettingPlayerPrefs

GetIntKeyPlayerPref

Returns the value for a given key from PlayerPrefs.

Parameters

Name

Type

Required

Description

keyname

string

Yes

Key to be retreived

Returns

  • int

[Test]
public void TestDeleteKey()
{
    altUnityDriver.DeletePlayerPref();
    altUnityDriver.SetKeyPlayerPref("test", 1);
    var val = altUnityDriver.GetIntKeyPlayerPref("test");
    Assert.AreEqual(1, val);
    altUnityDriver.DeleteKeyPlayerPref("test");
    try
    {
        altUnityDriver.GetIntKeyPlayerPref("test");
        Assert.Fail();
    }
    catch (NotFoundException exception)
    {
        Assert.AreEqual("notFound", exception.Message);
    }

}

GetFloatKeyPlayerPref

Returns the value for a given key from PlayerPrefs.

Parameters

Name

Type

Required

Description

keyname

string

Yes

Key to be retreived

Returns

  • float

[Test]
public void TestDeleteKey()
{
    altUnityDriver.DeletePlayerPref();
    altUnityDriver.SetKeyPlayerPref("test", 1.0f);
    var val = altUnityDriver.GetFloatKeyPlayerPref("test");
    Assert.AreEqual(1.0f, val);
    altUnityDriver.DeleteKeyPlayerPref("test");
    try
    {
        altUnityDriver.GetFloatKeyPlayerPref("test");
        Assert.Fail();
    }
    catch (NotFoundException exception)
    {
        Assert.AreEqual("notFound", exception.Message);
    }

}

GetStringKeyPlayerPref

Returns the value for a given key from PlayerPrefs.

Parameters

Name

Type

Required

Description

keyname

string

Yes

Key to be retreived

Returns

  • string

[Test]
public void TestDeleteKey()
{
    altUnityDriver.DeletePlayerPref();
    altUnityDriver.SetKeyPlayerPref("test", "1");
    var val = altUnityDriver.GetStringKeyPlayerPref("test");
    Assert.AreEqual("1", val);
    altUnityDriver.DeleteKeyPlayerPref("test");
    try
    {
        altUnityDriver.GetStringKeyPlayerPref("test");
        Assert.Fail();
    }
    catch (NotFoundException exception)
    {
        Assert.AreEqual("notFound", exception.Message);
    }

}
SettingPlayerPrefs

SetKeyPlayerPref

Sets the value for a given key in PlayerPrefs.

Parameters

Name

Type

Required

Description

keyname

string

Yes

Key to be set

value

integer/float/string

Yes

Value to be set

Returns

  • Nothing

Examples

[Test]
public void TestDeleteKey()
{
    altUnityDriver.DeletePlayerPref();
    altUnityDriver.SetKeyPlayerPref("test", "1");
    var val = altUnityDriver.GetStringKeyPlayerPref("test");
    Assert.AreEqual("1", val);
    altUnityDriver.DeleteKeyPlayerPref("test");
    try
    {
        altUnityDriver.GetStringKeyPlayerPref("test");
        Assert.Fail();
    }
    catch (NotFoundException exception)
    {
        Assert.AreEqual("notFound", exception.Message);
    }

}

DeleteKeyPlayerPref

Removes key and its corresponding value from PlayerPrefs.

Parameters

Name Type Required Description
keyname sting Yes Key to be deleted

Returns

  • Nothing

Examples

[Test]
public void TestDeleteKey()
{
    altUnityDriver.DeletePlayerPref();
    altUnityDriver.SetKeyPlayerPref("test", 1);
    var val = altUnityDriver.GetIntKeyPlayerPref("test");
    Assert.AreEqual(1, val);
    altUnityDriver.DeleteKeyPlayerPref("test");
    try
    {
        altUnityDriver.GetIntKeyPlayerPref("test");
        Assert.Fail();
    }
    catch (NotFoundException exception)
    {
        Assert.AreEqual("notFound", exception.Message);
    }

}

DeletePlayerPref

Removes all keys and values from PlayerPref.

Parameters

None

Returns

  • Nothing

Examples

[Test]
public void TestSetKeyInt()
{
    altUnityDriver.DeletePlayerPref();
    altUnityDriver.SetKeyPlayerPref("test", 1);
    var val = altUnityDriver.GetIntKeyPlayerPref("test");
    Assert.AreEqual(1, val);
}

GetCurrentScene

Returns the current active scene.

Parameters

None

Returns

  • String

Examples

[Test]
public void TestGetCurrentScene()
{
    altUnityDriver.LoadScene("Scene 1 AltUnityDriverTestScene");
    Assert.AreEqual("Scene 1 AltUnityDriverTestScene", altUnityDriver.GetCurrentScene());
}

LoadScene

Loads the scene mentioned by its name.

Parameters

Name Type Required Description
scene string Yes Name of the scene to be loaded
loadSingle bool No Flag to set the mode how to load the scene. Default value is true. If set to false the scene will be loaded additive, together with the current loaded scenes.

Returns

  • Nothing

Examples

[Test]
public void TestGetCurrentScene()
{
    altUnityDriver.LoadScene("Scene 1 AltUnityDriverTestScene",true);
    Assert.AreEqual("Scene 1 AltUnityDriverTestScene", altUnityDriver.GetCurrentScene());
}

UnloadScene

Unloads the scene mentioned by its name.

Parameters

Name Type Required Description
scene string Yes Name of the scene to be unloaded

Returns

  • Nothing

Examples

[Test]
public void TestUnloadScene()
{
    altUnityDriver.LoadScene("Scene 2 Draggable Panel", false);
    Assert.AreEqual(2, altUnityDriver.GetAllLoadedScenes().Count);
    altUnityDriver.UnloadScene("Scene 2 Draggable Panel");
    Assert.AreEqual(1, altUnityDriver.GetAllLoadedScenes().Count);
    Assert.AreEqual("Scene 1 AltUnityDriverTestScene", altUnityDriver.GetAllLoadedScenes()[0]);
}

GetAllLoadedScenes

Returns all the scenes that have been loaded.

Parameters

  • None

Returns

  • List of strings

Examples

[Test]
 public void TestGetAllLoadedScenes()
 {
     altUnityDriver.LoadScene("Scene 1 AltUnityDriverTestScene");
     System.Collections.Generic.List<string> loadedSceneNames = altUnityDriver.GetAllLoadedScenes();
     Assert.AreEqual(loadedSceneNames.Count, 1);
     altUnityDriver.LoadScene("Scene 2 Draggable Panel", false);
     altUnityDriver.LoadScene("Scene 3 Drag And Drop", false);
     altUnityDriver.LoadScene("Scene 4 No Cameras", false);
     altUnityDriver.LoadScene("Scene 5 Keyboard Input", false);
     loadedSceneNames = altUnityDriver.GetAllLoadedScenes();
     Assert.AreEqual(loadedSceneNames.Count, 5);
 }

WaitForCurrentSceneToBe

Waits for the scene to be loaded for a specified amount of time. It returns the name of the current scene.

Parameters

Name Type Required Description
sceneName string Yes The name of the scene to wait for.
timeout double Optional The time measured in seconds to wait for the specified scene.
interval double Optional How often to check that the scene was loaded in the given timeout.

Returns

  • string

Examples

[Test]
public void TestWaitForCurrentSceneToBe()
{
    const string name = "Scene 1 AltUnityDriverTestScene";
    var timeStart = DateTime.Now;
    var currentScene = altUnityDriver.WaitForCurrentSceneToBe(name);
    var timeEnd = DateTime.Now;
    var time = timeEnd - timeStart;
    Assert.Less(time.TotalSeconds, 20);
    Assert.NotNull(currentScene);
    Assert.AreEqual("Scene 1 AltUnityDriverTestScene", currentScene);
}

GetTimeScale

Returns the value of the time scale.

Parameters

None

Returns

  • float

Examples

[Test]
public void TestTimeScale()
{
    altUnityDriver.SetTimeScale(0.1f);
    Thread.Sleep(1000);
    var timeScaleFromGame = altUnityDriver.GetTimeScale();
    Assert.AreEqual(0.1f, timeScaleFromGame);
}

SetTimeScale

Sets the value of the time scale.

Parameters

Name Type Required Description
timeScale float Yes The value you want to set the time scale to.

Returns

  • None

Examples

[Test]
public void TestTimeScale()
{
    altUnityDriver.SetTimeScale(0.1f);
    Thread.Sleep(1000);
    var timeScaleFromGame = altUnityDriver.GetTimeScale();
    Assert.AreEqual(0.1f, timeScaleFromGame);
}

CallStaticMethod

Invokes static methods from your game.

Parameters

Name Type Required Description
typeName string Yes name of the script. If the script has a namespace the format should look like this: "namespace.typeName" )
methodName string Yes The name of the public method that we want to call. If the method is inside a static property/field to be able to call that method, methodName need to be the following format "propertyName.MethodName"
parameters array No an array containing the serialized parameters to be sent to the component method.
typeOfParameters array No an array containing the serialized type of parameters to be sent to the component method.
assemblyName string No name of the assembly containing the script

Returns

  • This is a generic method. The return type depends on the type parameter.

Examples

[Test]
public void TestCallStaticMethod()
{

    altUnityDriver.CallStaticMethod<string>("UnityEngine.PlayerPrefs", "SetInt", new[] { "Test", "1" });
    int a = altUnityDriver.CallStaticMethod<int>("UnityEngine.PlayerPrefs", "GetInt", new[] { "Test", "2" });
    Assert.AreEqual(1, a);

}

GetStaticProperty

Gets the value of the static field or property given as parameter.

Parameters

Name Type Required Description
componentName string Yes The name of the component which has the static field or property to be retrieved.
propertyName string Yes The name of the static field or property to be retrieved.
assembly string Yes The name of the assembly the component belongs to.
maxDepth int Optional The maximum depth in the hierarchy to look for the static field or property. Its value is 2 by default.

Returns

  • This is a generic method. The return type depends on the type of the static field or property to be retrieved.

Examples

[Test] 
public void TestGetStaticProperty()
{
    altUnityDriver.CallStaticMethod<string>("UnityEngine.Screen", "SetResolution", new string[] {"1920", "1080", "true"}, new string[] {"System.Int32", "System.Int32", "System.Boolean"}, "UnityEngine.CoreModule");
    var width = altUnityDriver.GetStaticProperty<int>("UnityEngine.Screen", "currentResolution.width", "UnityEngine.CoreModule");
    Assert.AreEqual(1920, width);
}

AltUnity Commands

SetServerLogging

Sets the level of logging in AltUnity Tester instrumented Unity application

Parameters

Name Type Required Description
logger AltUnityLogger Yes The type of logger
logLevel AltUnityLogLevel Yes The logging level

Returns

  • Nothing

Examples

altUnityDriver.SetServerLogging(AltUnityLogger.File, AltUnityLogLevel.Off);
altUnityDriver.SetServerLogging(AltUnityLogger.Unity, AltUnityLogLevel.Info);

AltUnityObject

The AltUnityObject class represents the objects present in the game and it allows you through the methods listed below to interact with them. It is the return type of the methods in the FindObjects category.

Fields

Name Type Description
name string The name of the object
id int The objects's id
x int The value for x axis coordinate on screen
y int The value for y axis coordinate on screen
mobileY int The value for y axis for appium
type string Object's type, for objects from the game is gameObject
enabled bool The local active state of the object. Note that an object may be inactive because a parent is not active, even if this returns true.
worldX float The value for x axis coordinate in the game's world
worldY float The value for y axis coordinate in the game's world
worldZ float The value for z axis coordinate in the game's world
idCamera int The camera's id
transformId int The transform's component id
parentId int The transform parent's id. It's obsolete. Use transformParentId instead
transformParentId int The transform parent's id.

The available methods are the following:

Object Commands

CallComponentMethod

Invokes a method from an existing component of the object.

Parameters

Name Type Required Description
componentName string Yes name of the component. If the component has a namespace the format should look like this: "namespace.componentName" )
methodName string Yes The name of the public method that will be called. If the method is inside a property/field to be able to call that method, methodName need to be the following format "propertyName.MethodName"
parameters array No an array containing the serialized parameters to be sent to the component method.
typeOfParameters array No an array containing the serialized type of parameters to be sent to the component method.
assemblyName string No name of the assembly containing the component

Returns

  • This is a generic method. The return type depends on the type parameter.

Examples

[Test]
public void TestCallMethodWithAssembly(){

    AltUnityObject capsule = altUnityDriver.FindObject(By.NAME, "Capsule");
    var initialRotation = capsule.GetComponentProperty("UnityEngine.Transform", "rotation");
    capsule.CallComponentMethod<string>("UnityEngine.Transform", "Rotate", new[] { "10", "10", "10" }, new[] { "System.Single", "System.Single", "System.Single" }, "UnityEngine.CoreModule");
    AltUnityObject capsuleAfterRotation = altUnityDriver.FindObject(By.NAME, "Capsule");
    var finalRotation = capsuleAfterRotation.GetComponentProperty("UnityEngine.Transform", "rotation";
    Assert.AreNotEqual(initialRotation, finalRotation);
}

GetComponentProperty

Returns the value of the given component property.

Parameters

Name Type Required Description
componentName string Yes name of the component. If the component has a namespace the format should look like this: "namespace.componentName"
propertyName string Yes Name of the property of which value you want. If the property is an array you can specify which element of the array to return by doing property[index], or if you want a property inside of another property you can get by doing property.property2 for example position.x.
assemblyName string No name of the assembly containing the component
maxDepth int No Set how deep the serialization of the property to do. For example for position property in transform the result are following: maxDepth=2 {"normalized":{"magnitude":1.0, "sqrMagnitude":1.0, "x":0.871575534, "y":0.490261227, "z":0.0}, "magnitude":1101.45361, "sqrMagnitude":1213200.0, "x":960.0,"y":540.0, "z":0.0} and for maxDepth=1 :{"normalized":{},"magnitude":1101.45361, "sqrMagnitude":1213200.0, "x":960.0,"y":540.0, "z":0.0}

Returns

  • String

Examples

[Test]
public void TestGetComponentProperty()
{
    const string componentName = "AltUnityRunner";
    const string propertyName = "SocketPortNumber";
    var altUnityObject = altUnityDriver.FindObject(By.NAME,"AltUnityRunnerPrefab");
    Assert.NotNull(altUnityObject);
    var propertyValue = altUnityObject.GetComponentProperty(componentName, propertyName);
    Assert.AreEqual(propertyValue, "13000");
}

SetComponentProperty

Sets value of the given component property.

Parameters

Name Type Required Description
componentName string Yes name of the component. If the component has a namespace the format should look like this: "namespace.componentName" )
propertyName string Yes name of the property of which value you want to set
value string Yes the value to be set for the chosen component's property
assemblyName string No name of the assembly containing the component. It is NULL by default

Returns

  • String

Examples

[Test]
public void TestSetComponentProperty()
{
    const string componentName = "Capsule";
    const string propertyName = "stringToSetFromTests";
    var altUnityObject = altUnityDriver.FindObject(By.NAME, "Capsule");
    Assert.NotNull(altUnityObject);
    var propertyValue = altUnityObject.SetComponentProperty(componentName, propertyName, "2");
    Assert.AreEqual("valueSet", propertyValue);
    propertyValue = altUnityObject.GetComponentProperty(componentName, propertyName);
    Assert.AreEqual("2", propertyValue);
}

GetText

Returns text value from a Button, Text, InputField. This also works with TextMeshPro elements.

Parameters

None

Returns

  • String

Examples

[Test]
public void TestWaitForObjectWithText()
{
    const string name = "CapsuleInfo";
    string text = altUnityDriver.FindObject(By.NAME,name).GetText();
    var timeStart = DateTime.Now;
    var altUnityObject = altUnityDriver.WaitForObject(By.PATH, "//" + name + "[@text=" + text + "]");
    var timeEnd = DateTime.Now;
    var time = timeEnd - timeStart;
    Assert.Less(time.TotalSeconds, 20);
    Assert.NotNull(altUnityObject);
    Assert.AreEqual(altUnityObject.GetText(), text);

}

SetText

Sets text value for a Button, Text, InputField. This also works with TextMeshPro elements.

Parameters

Name Type Required Description
text string Yes text to be set

Returns

  • AltUnityObject

Examples

[Test]
public void TestSetTextForElement()
{
    const string name = "InputField";
    const string text = "InputFieldTest";
    var input = altUnityDriver.FindObject(By.NAME, name).SetText(text);
    Assert.NotNull(input);
    Assert.AreEqual(input.GetText(), text);
}

Tap

Tap current object

Parameters

Name Type Required Default Description
count int No 1 Number of taps
interval float No 0.1 Interval between taps in seconds
wait boolean No true Wait for command to finish

Returns

  • void

Examples

[Test]
public void TestTap()
{
    var counterButton = altUnityDriver.FindObject(By.NAME, "ButtonCounter");
    var counterButtonText = altUnityDriver.FindObject(By.NAME, "ButtonCounter/Text");
    counterButton.Tap();
    altUnityDriver.WaitForObject(By.PATH, "//ButtonCounter/Text[@text=1]");
}

Click

Click current object

Parameters

Name Type Required Default Description
count int No 1 Number of clicks
interval float No 0.1 Interval between clicks in seconds
wait boolean No true Wait for command to finish

Returns

  • void

Examples

[Test]
public void TestClickElement()
{
    var counterButton = altUnityDriver.FindObject(By.NAME, "ButtonCounter");
    var counterButtonText = altUnityDriver.FindObject(By.NAME, "ButtonCounter/Text");
    counterButton.Click();
    altUnityDriver.WaitForObject(By.PATH, "//ButtonCounter/Text[@text=1]");
}

PointerDown

Simulates pointer down action on the object.

Parameters

None

Returns

  • AltUnityObject

Examples

[Test]
public void TestPointerDownCommand()
{
    var panel = altUnityDriver.FindObject(By.NAME, "Panel");
    var color1 = panel.GetComponentProperty("PanelScript","normalColor");
    panel.PointerDownFromObject();
    Thread.Sleep(1000);
    var color2 = panel.GetComponentProperty("PanelScript","highlightColor");
    Assert.AreNotEqual(color1, color2);
}

PointerUp

Simulates pointer up action on the object.

Parameters

None

Returns

  • AltUnityObject

Examples

[Test]
public void TestPointerUpCommand()
{
    var panel = altUnityDriver.FindObject(By.NAME, "Panel");
    var color1 = panel.GetComponentProperty("PanelScript","normalColor");
    panel.PointerDownFromObject();
    Thread.Sleep(1000);
    panel.PointerUpFromObject();
    var color2 = panel.GetComponentProperty("PanelScript","highlightColor");
    Assert.AreEqual(color1, color2);
}

PointerEnter

Simulates pointer enter action on the object.

Parameters

None

Returns

  • AltUnityObject

Examples

[Test]
public void TestPointerEnterAndExit()
{
    var altUnityObject = altUnityDriver.FindObject(By.NAME,"Drop Image");
    var color1 = altUnityObject.GetComponentProperty("DropMe", "highlightColor");
    altUnityDriver.FindObject(By.NAME,"Drop Image").PointerEnterObject();
    var color2 = altUnityObject.GetComponentProperty("DropMe", "highlightColor");
    Assert.AreNotEqual(color1,color2);
    altUnityDriver.FindObject(By.NAME,"Drop Image").PointerExitObject();
    var color3 = altUnityObject.GetComponentProperty("DropMe", "highlightColor");
    Assert.AreNotEqual(color3, color2);
    Assert.AreEqual(color1,color3);
}

PointerExit

Simulates pointer exit action on the object.

Parameters

None

Returns

  • AltUnityObject

Examples

[Test]
public void TestPointerEnterAndExit()
{
    var altUnityObject = altUnityDriver.FindObject(By.NAME,"Drop Image");
    var color1 = altUnityObject.GetComponentProperty("DropMe", "highlightColor");
    altUnityDriver.FindObject(By.NAME,"Drop Image").PointerEnterObject();
    var color2 = altUnityObject.GetComponentProperty("DropMe", "highlightColor");
    Assert.AreNotEqual(color1,color2);
    altUnityDriver.FindObject(By.NAME,"Drop Image").PointerExitObject();
    var color3 = altUnityObject.GetComponentProperty("DropMe", "highlightColor");
    Assert.AreNotEqual(color3, color2);
    Assert.AreEqual(color1,color3);
}

GetParent

Returns the parent of the AltUnity object on which it is called.

Parameters

None

Returns

  • AltUnityObject

Examples

[Test]
public void TestGetParent()
{
    var altUnityObject = altUnityDriver.FindObject(By.NAME, "Panel", By.NAME, "Main Camera");
    var altUnityObjectParent = altUnityObject.getParent();
    Assert.AreEqual("Panel Drag Area", altUnityObjectParent.name);
}

BY-Selector

It is used in find objects methods to set the criteria of which the objects are searched. Currenty there are 7 types implemented:

  • By.TAG - search for objects that have a specific tag

  • By.LAYER - search for objects that are set on a specific layer

  • By.NAME - search for objects that are named in a certain way

  • By.COMPONENT - search for objects that have certain component

  • By.ID - search for objects that have assigned a certain id (every object has an unique id so this criteria always will return 1 or 0 objects). Id checks for InstanceId and AltId

  • By.TEXT - search for objects that have a certain text

  • By.PATH - search for objects that respect a certain path

Searching object by PATH

The following selecting nodes and attributes are implemented:

  • object - Selects all object with the name “object”

  • / - Selects from the root node

  • // - Selects nodes in the document from the current node that match the selection no matter where they are

  • .. - Selects the parent of the current node

  • * - Matches any element node

  • contains - Selects objects that contain a certain string in the name

  • [n-th] - Selects n-th child of the current node. 0 - represents the first child, 1 - is the second child and so on. -1 -represents the last child

  • @tag

  • @layer

  • @name

  • @component

  • @id

  • @text

Examples

//NameOfParent/NameOfChild/*

//NameOfParent/NameOfChild//*

altUnityDriver.FindObjects(By.PATH, "//Canvas/Panel/*")
  • Returns all direct children from Panel

altUnityDriver.FindObjects(By.PATH, "//Canvas/Panel//*")
  • Returns all children from Panel

Escaping characters

There are several characters that you need to escape when you try to find an object. Some examples characters are the symbols for Request separator and Request ending, by default this are ; and & but can be changed in Server settings. If you don’t escape this characters the whole request is invalid and might shut down the server. Other characters are !, [, ], (, ), /, \, . or ,. This characters are used in searching algorithm and if not escaped might return the wrong object or not found at all. To escape all the characters mentioned before just add \\ before each character you want to escape.

Example: //Q&A - not escaped //Q\\&A - escaped

AltId

Is a solution offered by AltUnity Tester in order to find object easier. This is an unique identifier stored in an component and added to every object. A limitation of this is that only the object already in the scene before building the game will have an AltId. Object instantiated during run time will not have an AltId

To add AltId to every object simply just click AddAltIdToEveryObject from AltUnityTester menu. addAltId