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 Server that is running inside the game. In the constructor, we need to tell the driver where (on what IP and on what port) the server is running. We can also set some more advanced parameters, as shown in the table below:

Parameters

Name Type Required Description
tcp_ip string No The default value for this is "127.0.0.1"
tcp_port int No The default value for this is 13000
requestSeparator string No The default value for this is ";"
requestEnding string No The default value for this is "&"
logFlag boolean No The default value for this is false

For more information about the AltUnityDriver parameters you can read the Server Settings page.

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
cameraName 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 TestFindElement()
{
    const string name = "Capsule";
    var altElement = altUnityDriver.FindObject(By.NAME,name);
    Assert.NotNull(altElement);
    Assert.AreEqual(name, altElement.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
cameraName 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 altElements = altUnityDriver.FindObjects(By.TAG,"plane");
    Assert.AreEqual(2, altElements.Count);
    foreach(var altElement in altElements)
    {
        Assert.AreEqual("Plane", altElement.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
cameraName 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 altElement = altUnityDriver.FindObjectWhichContains(By.NAME, "Event");
     Assert.AreEqual("EventSystem", altElement.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
cameraName 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 altelement = altUnityDriver.FindObjectWhichContain(By.NAME, "Event");
  Assert.AreEqual("EventSystem", altElement.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
cameraName 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 TestGetAllEnabledElements()
{

    var altElements = altUnityDriver.GetAllElements(enabled: true);
    Assert.IsNotEmpty(altElements);
    string listOfElements="";
        foreach(var element in altElements){
        listOfElements=element.name+"; ";
    }
    Debug.Log(listOfElements);
    Assert.AreEqual(19, altElements.Count);
    Assert.IsNotNull(altElements.Where(p => p.name == "Capsule"));
    Assert.IsNotNull(altElements.Where(p => p.name == "Main Camera"));
    Assert.IsNotNull(altElements.Where(p => p.name == "Directional Light"));
    Assert.IsNotNull(altElements.Where(p => p.name == "Plane"));
    Assert.IsNotNull(altElements.Where(p => p.name == "Canvas"));
    Assert.IsNotNull(altElements.Where(p => p.name == "EventSystem"));
    Assert.IsNotNull(altElements.Where(p => p.name == "AltUnityRunner"));
    Assert.IsNotNull(altElements.Where(p => p.name == "CapsuleInfo"));
    Assert.IsNotNull(altElements.Where(p => p.name == "UIButton"));
    Assert.IsNotNull(altElements.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
cameraName 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
cameraName 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 altElement = altUnityDriver.WaitForObjectWhichContains(By.NAME, "Canva");
    Assert.AreEqual("Canvas", altElement.name);
}

WaitForObjectWithText

Waits until it finds an object that respect the given criteria and it has the text you are looking for or times run 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
text string Yes Text that the intented object should have
cameraBy By No Set what criteria to use in order to find the camera
cameraName 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 TestWaitForElementWithText()
{
    const string name = "CapsuleInfo";
    string text = altUnityDriver.FindObject(By.NAME,name).GetText();
    var timeStart = DateTime.Now;
    var altElement = altUnityDriver.WaitForObjectWithText(By.NAME, name, text);
    var timeEnd = DateTime.Now;
    var time = timeEnd - timeStart;
    Assert.Less(time.TotalSeconds, 20);
    Assert.NotNull(altElement);
    Assert.AreEqual(altElement.GetText(), text);
}

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
cameraName 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.
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));
}

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 KeyCode(C#)/string(python/java) Yes Name of the button. Please check KeyCode for C# or key section for python/java for more information about key names
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 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);
}

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 KeyCode(C#)/string(python/java) Yes Name of the button. Please check KeyCode for C# or key section for python/java for more information about key names
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 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);
}

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 move the mouse from current position to the set location.

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 move the mouse from current position to the set location.

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 altElement1 = altUnityDriver.FindObject(By.NAME,"Drag Image1");
    var altElement2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    altUnityDriver.SwipeAndWait(new AltUnityVector2(altElement1.x, altElement1.y), new AltUnityVector2(altElement2.x, altElement2.y), 1);

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

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


    altElement1 = altUnityDriver.FindObject(By.NAME,"Drag Image1");
    altElement2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    altUnityDriver.SwipeAndWait(new AltUnityVector2(altElement1.x, altElement1.y), new AltUnityVector2(altElement2.x, altElement2.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 altElement1 = altUnityDriver.FindObject(By.NAME,"Drag Image1");
    var altElement2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    altUnityDriver.Swipe(new AltUnityVector2(altElement1.x, altElement1.y), new AltUnityVector2(altElement2.x, altElement2.y), 1);

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

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


    altElement1 = altUnityDriver.FindObject(By.NAME,"Drag Image1");
    altElement2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    altUnityDriver.Swipe(new AltUnityVector2(altElement1.x, altElement1.y), new AltUnityVector2(altElement2.x, altElement2.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 altElement = altUnityDriver.FindObject(By.NAME,"Resize Zone");
    var position = new AltUnityVector2(altElement.x, altElement.y);
    var pos = new []
    {
        altElement.getScreenPosition(),
        new AltUnityVector2(altElement.x - 200, altElement.y - 200),
        new AltUnityVector2(altElement.x - 300, altElement.y - 100),
        new AltUnityVector2(altElement.x - 50, altElement.y - 100),
        new AltUnityVector2(altElement.x - 100, altElement.y - 100)
    };
    altUnityDriver.MultipointSwipe(pos, 4);

    Thread.Sleep(4000);

    altElement = altUnityDriver.FindObject(By.NAME,"Resize Zone");
    var position2 = new AltUnityVector2(altElement.x, altElement.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 altElement1 = altUnityDriver.FindObject(By.NAME,"Drag Image1");
    var altElement2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    altUnityDriver.MultipointSwipe(new []{new AltUnityVector2(altElement1.x, altElement1.y), new AltUnityVector2(altElement2.x, altElement2.y)}, 2);
    Thread.Sleep(2000);

    altElement1 = altUnityDriver.FindObject(By.NAME,"Drag Image1");
    altElement2 = altUnityDriver.FindObject(By.NAME,"Drop Box1");
    var altElement3 = altUnityDriver.FindObject(By.NAME,"Drop Box2");
    var positions = new[]
    {
        new AltUnityVector2(altElement1.x, altElement1.y),
        new AltUnityVector2(altElement2.x, altElement2.y),
        new AltUnityVector2(altElement3.x, altElement3.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 altElement = altUnityDriver.FindObject(By.NAME,name);
    altUnityDriver.Click(altElement.getScreenPosition());
    Assert.AreEqual(name, altElement.name);
    altUnityDriver.WaitForObjectWithText(By.NAME,"CapsuleInfo", "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 altElement = altUnityDriver.FindObject(By.NAME,name);
    altUnityDriver.Tap(altElement.getScreenPosition());
    Assert.AreEqual(name, altElement.name);
    altUnityDriver.WaitForObjectWithText(By.NAME,"CapsuleInfo", "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("error: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("error: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("error: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("error: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("error: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);
 }

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 string Yes a string containing the serialized parameters to be sent to the component method. This uses '?' to separate between parameters, like this: 'some string ? [1,2,3]' - this represents two parameters "some string" and "[1,2,3]" Each parameter will be deserialized to match the correct type, so '[1,2,3] will deserialized to an array of integers, '1' will be an integer etc.
typeOfParameters string No a string containing the serialized type of parameters to be sent to the component method. This uses '?' to separate between parameters, like this: 'System.Int32 ? System.Int32' - this represents that the signature of the method has two integers
assemblyName string No name of the assembly containing the script

Returns

  • String. The value returned by the method is serialized to a JSON object and parsed as string.

Examples

[Test]
public void TestCallStaticMethod()
{

    altUnityDriver.CallStaticMethods("UnityEngine.PlayerPrefs", "SetInt", "Test?1");
    int a = Int32.Parse(altUnityDriver.CallStaticMethods("UnityEngine.PlayerPrefs", "GetInt", "Test?2"));
    Assert.AreEqual(1, a);

}

AltUnity Commands

SetServerLogging

Sets the level of logging on AltUnity Server

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 string Yes a string containing the serialized parameters to be sent to the component method. This uses '?' to separate between parameters, like this: 'some string ? [1,2,3]' - this represents two parameters "some string" and "[1,2,3]" Each parameter will be deserialized to match the correct type, so '[1,2,3] will deserialized to an array of integers, '1' will be an integer etc. Optional parameters are required to be set if the method has any in order to find the correct method
typeOfParameters string No a string containing the serialized type of parameters to be sent to the component method. This uses '?' to separate between parameters, like this: 'System.Int32 ? System.Int32' - this represents that the signature of the method has two integers
assemblyName string No name of the assembly containing the component

Returns

  • String. The value returned by the method is serialized to a JSON object and parsed as string.

Examples

[Test]
public void TestCallMethodWithAssembly(){
    AltUnityObject capsule = altUnityDriver.FindObject(By.NAME,"Capsule");
    var initialRotation = capsule.GetComponentProperty("UnityEngine.Transform", "rotation");
    capsule.CallComponentMethod("UnityEngine.Transform", "Rotate", "10?10?10", "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 altElement = altUnityDriver.FindObject(By.NAME,"AltUnityRunnerPrefab");
    Assert.NotNull(altElement);
    var propertyValue = altElement.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 altElement = altUnityDriver.FindObject(By.NAME, "Capsule");
    Assert.NotNull(altElement);
    var propertyValue = altElement.SetComponentProperty(componentName, propertyName, "2");
    Assert.AreEqual("valueSet", propertyValue);
    propertyValue = altElement.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 TestWaitForElementWithText()
{
    const string name = "CapsuleInfo";
    string text = altUnityDriver.FindObject(By.NAME,name).GetText();
    var timeStart = DateTime.Now;
    var altElement = altUnityDriver.WaitForObjectWithText(By.NAME, name, text);
    var timeEnd = DateTime.Now;
    var time = timeEnd - timeStart;
    Assert.Less(time.TotalSeconds, 20);
    Assert.NotNull(altElement);
    Assert.AreEqual(altElement.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 altElement = altUnityDriver.FindObject(By.NAME,"Drop Image");
    var color1 = altElement.GetComponentProperty("DropMe", "highlightColor");
    altUnityDriver.FindObject(By.NAME,"Drop Image").PointerEnterObject();
    var color2 = altElement.GetComponentProperty("DropMe", "highlightColor");
    Assert.AreNotEqual(color1,color2);
    altUnityDriver.FindObject(By.NAME,"Drop Image").PointerExitObject();
    var color3 = altElement.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 altElement = altUnityDriver.FindObject(By.NAME,"Drop Image");
    var color1 = altElement.GetComponentProperty("DropMe", "highlightColor");
    altUnityDriver.FindObject(By.NAME,"Drop Image").PointerEnterObject();
    var color2 = altElement.GetComponentProperty("DropMe", "highlightColor");
    Assert.AreNotEqual(color1,color2);
    altUnityDriver.FindObject(By.NAME,"Drop Image").PointerExitObject();
    var color3 = altElement.GetComponentProperty("DropMe", "highlightColor");
    Assert.AreNotEqual(color3, color2);
    Assert.AreEqual(color1,color3);
}

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

AltUnityPortForwarding

API to interact with adb and iproxy programatically

ForwardAndroid

Calls adb forward [-s {deviceId}] tcp:{localPort} tcp:{remotePort}

Parameters

Name Type Required Description
localPort int No The local port to forward from
remotePort int No The device port to forward to
deviceId string No The id of the device
adbPath string No The adb path. If no adb path is provided, it tries to use adb from ${ANDROID_SDK_ROOT}/platform-tools/adb. If ANDROID_SDK_ROOT env varibale is not set, it tries to execute adb from PATH.

RemoveForwardAndroid

Calls adb forward --remove [-s {deviceId}] tcp:{localPort} or adb forward --remove-all if no localport provided

Parameters

Name Type Required Description
localPort int No The local port to be removed
deviceId string No The id of the device to be removed
adbPath string No The adb path. If no adb path is provided, it tries to use adb from ${ANDROID_SDK_ROOT}/platform-tools/adb. If ANDROID_SDK_ROOT env varibale is not set, it tries to execute adb from PATH.

RemoveAllForwardAndroid

Calls adb forward --remove-all

Parameters

Name Type Required Description
adbPath string No The adb path. If no adb path is provided, it tries to use adb from ${ANDROID_SDK_ROOT}/platform-tools/adb. If ANDROID_SDK_ROOT env varibale is not set, it tries to execute adb from PATH.

ForwardIos

Calls iproxy {localport} {remotePort} -u {deviceId}.

Requires iproxy 2.0.2.

Parameters

Name Type Required Description
localPort int No The local port to forward from
remotePort int No The device port to forward to
deviceId string No The id of the device
iproxyPath string No The path to iProxy. If iproxyPath is not provided, iproxy should be available in PATH

KillAllIproxyProcess

Kills iproxy process by name. Calls killall iproxy