API

If you are looking for information on a specific function, class or method, this part of the documentation is for you.

AltDriver

The AltDriver class represents the main app driver component. When you instantiate an AltDriver in your tests, you can use it to “drive” your app like one of your users would, by interacting with all the app objects, their properties and methods.

An AltDriver instance will connect to the running instrumented Unity application. In the constructor, we need to tell the driver where (on what IP and on what port) the instrumented Unity App with a specific name is running and for how many seconds to let the communication opened.

Parameters

AltDriver Parameters

Name

Type

Required

Description

host

string

No

The IP or hostname AltTester® Unity SDK is listening on. The default value is: 127.0.0.1

port

int

No

The default value is: 13000

appName

string

No

The name of the Unity application. The default value is: __default__

enableLogging

boolean

No

The default value is: false

connectTimeout

int

No

The connect timeout in seconds. The default value is: 60

platform

string

No

The platform of the Unity application. The default value is: unknown

platformVersion

string

No

The platform version of the Unity application. The default value is: unknown

deviceInstanceId

string

No

The device instance ID of the Unity application. The default value is: unknown

appId

string

No

The unique ID of the Unity application. The default value is: unknown

Examples

[Test]
public void MyTest()
{
    AltDriver altDriver = new AltDriver(host: "127.0.0.1", port: 13000);
}

Once you have an instance of the AltDriver, you can use all the available commands to interact with the app. 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 criteria.

Important

Indexer functionality was changed in 2.0.2 to match that of XPath and it no longer returns the n-th child of the object. Now it returns the n-th object that respects the selectors (Name, Component, Tag, etc.) from the objects with the same parent. The numbering starts from 0 so the first object has the index 0 then the second object has the index 1 and so on. For example //Button/Text[1] will return the second object named Text that is the child of the Button

Parameters

FindObject 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 the object will be compared to see if it respects 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 coordinates of the object will be calculated. If no camera is given, it will search through all cameras that are in the scene until some camera sees the object or return the screen coordinates 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

Examples

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

FindObjects

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

Important

Indexer functionality was changed in 2.0.2 to match that of XPath and it no longer returns the n-th child of the object. Now it returns the n-th object that respects the selectors (Name, Component, Tag, etc.) from the objects with the same parent. The numbering starts from 0 so the first object has the index 0 then the second object has the index 1 and so on. For example //Button/Text[1] will return the second object named Text that is the child of the Button

Parameters

FindObjects 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 the object will be compared to see if it respects 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 coordinates of the object will be calculated. If no camera is given, it will search through all cameras that are in the scene until some camera sees the object or return the screen coordinates 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 AltObjects or an empty list if no objects were found.

Examples

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

FindObjectWhichContains

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

Important

Indexer functionality was changed in 2.0.2 to match that of XPath and it no longer returns the n-th child of the object. Now it returns the n-th object that respects the selectors (Name, Component, Tag, etc.) from the objects with the same parent. The numbering starts from 0 so the first object has the index 0 then the second object has the index 1 and so on. For example //Button/Text[1] will return the second object named Text that is the child of the Button

Parameters

FindObjectWhichContains 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 the object will be compared to see if it respects 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 coordinates of the object will be calculated. If no camera is given, it will search through all cameras that are in the scene until some camera sees the object or return the screen coordinates 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

Examples

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

FindObjectsWhichContain

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

Important

Indexer functionality was changed in 2.0.2 to match that of XPath and it no longer returns the n-th child of the object. Now it returns the n-th object that respects the selectors (Name, Component, Tag, etc.) from the objects with the same parent. The numbering starts from 0 so the first object has the index 0 then the second object has the index 1 and so on. For example //Button/Text[1] will return the second object named Text that is the child of the Button

Parameters

FindObjectsWhichContain 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 the object will be compared to see if it respects 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 coordinates of the object will be calculated. If no camera is given, it will search through all cameras that are in the scene until some camera sees the object or return the screen coordinates 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 AltObjects or an empty list if no objects were found.

Examples

[Test]
public void TestFindObjects()
{
    var planes = altDriver.FindObjectsWhichContain(By.NAME, "Plane");
    Assert.AreEqual(3, planes.Count);
}

FindObjectAtCoordinates

Retrieves the Unity object at given coordinates.

Uses EventSystem.RaycastAll to find object. If no object is found then it uses UnityEngine.Physics.Raycast and UnityEngine.Physics2D.Raycast and returns the one closer to the camera.

Parameters

FindObjectAtCoordinates Parameters

Name

Type

Required

Description

coordinates

AltVector2

Yes

The screen coordinates.

Returns

  • AltObject - The UI object hit by event system Raycast, nothing otherwise.

Examples

[Test]
public void TestFindElementAtCoordinates()
{
    var counterButton = altDriver.FindObject(By.NAME, "ButtonCounter");
    var element = altDriver.FindObjectAtCoordinates(new AltVector2(80 + counterButton.x, 15 + counterButton.y));
    Assert.AreEqual("Text", element.name);
}

GetAllElements

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

Parameters

GetAllElements 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 coordinates of the object will be calculated. If no camera is given, it will search through all cameras that are in the scene until some camera sees the object or return the screen coordinates 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 AltObjects or an empty list if no objects were found.

Examples

[Test]
public void TestGetAllEnabledObjects()
{
    var altObjects = altDriver.GetAllElements(enabled: true);
    Assert.IsNotEmpty(altObjects);
}

WaitForObject

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

Important

Indexer functionality was changed in 2.0.2 to match that of XPath and it no longer returns the n-th child of the object. Now it returns the n-th object that respects the selectors (Name, Component, Tag, etc.) from the objects with the same parent. The numbering starts from 0 so the first object has the index 0 then the second object has the index 1 and so on. For example //Button/Text[1] will return the second object named Text that is the child of the Button

Parameters

WaitForObject 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 the object will be compared to see if it meets the criteria.

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 determine if they respect the criteria or not. If no camera is given, it will search through all cameras in the scene until some camera sees the object or return the screen coordinates of the object based on the last camera in the scene.

enabled

boolean

No

If true, matches only objects that are active in the hierarchy. If false, matches all objects.

timeout

double

No

The number of seconds it will wait for the object. The default is 20 seconds.

interval

double

No

The number of seconds after which it will retry finding the object. The interval should be smaller than the timeout.

Returns

Examples

[Test]
public void TestWaitForObject()
{
    const string name = "Capsule";
    var altObject = altDriver.WaitForObject(By.NAME, name);
}

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 criteria.

Important

Indexer functionality was changed in 2.0.2 to match that of XPath and it no longer returns the n-th child of the object. Now it returns the n-th object that respects the selectors (Name, Component, Tag, etc.) from the objects with the same parent. The numbering starts from 0 so the first object has the index 0 then the second object has the index 1 and so on. For example //Button/Text[1] will return the second object named Text that is the child of the Button

Parameters

WaitForObjectWhichContains 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 the object will be compared to determine if it meets the criteria.

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 determine if they respect the criteria or not. If no camera is given, it will search through all cameras in the scene until some camera sees the object or return the screen coordinates of the object based on the last camera in the scene.

enabled

boolean

No

If true, matches only objects that are active in the hierarchy. If false, matches all objects.

timeout

double

No

The number of seconds it will wait for the object. The default is 20 seconds.

interval

double

No

The number of seconds after which it will retry finding the object. The interval should be smaller than the timeout.

Returns

Examples

[Test]
public void TestWaitForObjectWhichContains()
{
    var altObject = altDriver.WaitForObjectWhichContains(By.NAME, "Canva");
}

WaitForObjectNotBePresent

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

Important

Indexer functionality was changed in 2.0.2 to match that of XPath and it no longer returns the n-th child of the object. Now it returns the n-th object that respects the selectors (Name, Component, Tag, etc.) from the objects with the same parent. The numbering starts from 0 so the first object has the index 0 then the second object has the index 1 and so on. For example //Button/Text[1] will return the second object named Text that is the child of the Button

Parameters

WaitForObjectNotBePresent 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 the object will be compared to determine if it meets the criteria.

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 determine if they respect the criteria or not. If no camera is given, it will search through all cameras in the scene until some camera sees the object or return the screen coordinates of the object based on the last camera in the scene.

enabled

boolean

No

If true, matches only objects that are active in the hierarchy. If false, matches all objects.

timeout

double

No

The number of seconds it will wait for the object. The default is 20 seconds.

interval

double

No

The number of seconds after which it will retry finding the object. The interval should be smaller than the timeout.

Returns

  • Nothing

Examples

[Test]
public void TestWaitForObjectNotBePresent()
{
    altDriver.WaitForObjectNotBePresent(By.NAME, "Capsulee");
}

SetCommandResponseTimeout

Sets the value for the command response timeout.

Parameters

SetCommandResponseTimeout Parameters

Name

Type

Required

Description

commandTimeout

int

Yes

The duration for a command response from the driver.

Returns

  • Nothing

Examples

altDriver.SetCommandResponseTimeout(commandTimeout);

GetDelayAfterCommand

Gets the current delay after a command.

Parameters

None

Returns

  • The current delay after a command.

Examples

altDriver.GetDelayAfterCommand();

SetDelayAfterCommand

Set the delay after a command.

Parameters

SetDelayAfterCommand Parameters

Name

Type

Required

Description

delay

int

Yes

The new delay after a command.

Returns

  • Nothing

Examples

altDriver.SetDelayAfterCommand(5);

SetImplicitTimeout

Sets an implicit timeout for all commands that use the timeout parameter.

Parameters

SetImplicitTimeout Parameters

Name

Type

Required

Description

timeout

positive double

Yes

The value of the new timeout. By default it is 20 seconds. Throws ArgumentOutOfRangeException in case of a negative timeout.

Returns

  • Nothing

Examples

altDriver.SetImplicitTimeout(5);

GetImplicitTimeout

Gets the implicit timeout for all commands that use the timeout parameter.

Parameters

None

Returns

  • The value of the implicit timeout in seconds.

Examples

altDriver.GetImplicitTimeout();

Input Actions

KeyDown

Simulates a key down.

Parameters

KeyDown Parameters

Name

Type

Required

Description

keyCode

AltKeyCode

Yes

The keyCode of the key simulated to be pressed.

power

int

No

A value between [-1,1] used for joysticks to indicate how hard the button was pressed.

Returns

  • Nothing

Examples

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

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

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

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

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

KeyUp

Simulates a key up.

Parameters

KeyUp Parameters

Name

Type

Required

Description

keyCode

AltKeyCode

Yes

The keyCode of the key simulated to be released.

Returns

  • Nothing

Examples

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

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

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

    altDriver.keyUp(kcode);
    var lastKeyUp = altDriver.FindObject(By.NAME, "LastKeyUpValue");

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

HoldButton

Simulates holding left click button down for a specified amount of time at given coordinates.

Parameters

HoldButton Parameters

Name

Type

Required

Default

Description

coordinates

AltVector2

Yes

The coordinates where the button is held down.

duration

float

No

0.1

The time measured in seconds to keep the button down.

wait

boolean

No

true

If set, waits for the command to finish.

Returns

  • Nothing

Examples

[Test]
public void TestHoldButton()
{
    var button = altDriver.FindObject(By.NAME, "UIButton");
    altDriver.HoldButton(button.GetScreenPosition(), 1);
    var capsuleInfo = altDriver.FindObject(By.NAME, "CapsuleInfo");
    var text = capsuleInfo.GetText();
    Assert.AreEqual(text, "UIButton clicked to jump capsule!");
}

MoveMouse

Simulate mouse movement in your app.

Parameters

MoveMouse Parameters

Name

Type

Required

Default

Description

coordinates

AltVector2

Yes

The screen coordinates.

duration

float

No

0.1

The time measured in seconds to move the mouse from the current mouse position to the set coordinates.

wait

boolean

No

true

If set, waits for the command to finish.

Returns

  • Nothing

Examples

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

    var stars = altDriver.FindObjectsWhichContain(By.NAME, "Star", cameraValue: "Player2");
    var pressingpoint1 = altDriver.FindObjectWhichContains(By.NAME, "PressingPoint1", cameraValue: "Player2");
    Assert.AreEqual(1, stars.Count);

    altDriver.MoveMouse(new AltVector2(pressingpoint1.x, pressingpoint1.y), 1);
    altDriver.PressKey(AltKeyCode.Mouse0, 0.1f);

    var pressingpoint2 = altDriver.FindObjectWhichContains(By.NAME, "PressingPoint2", cameraValue: "Player2");
    altDriver.MoveMouse(new AltVector2(pressingpoint2.x, pressingpoint2.y), 1);
    altDriver.PressKey(AltKeyCode.Mouse0, 0.1f);

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

PressKey

Simulates key press action in your app.

Parameters

PressKey Parameters

Name

Type

Required

Default

Description

keycode

AltKeyCode

Yes

The key code of the key simulated to be pressed.

power

float

No

1

A value between [-1,1] used for joysticks to indicate how hard the button was pressed.

duration

float

No

0.1

The time measured in seconds from the key press to the key release.

wait

boolean

No

true

If set, waits for the command to finish.

Returns

  • Nothing

Examples

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

    var stars = altDriver.FindObjectsWhichContain(By.NAME, "Star", cameraValue: "Player2");
    var pressingpoint1 = altDriver.FindObjectWhichContains(By.NAME, "PressingPoint1", cameraValue: "Player2");
    Assert.AreEqual(1, stars.Count);

    altDriver.MoveMouse(new AltVector2(pressingpoint1.x, pressingpoint1.y), 1);
    altDriver.PressKey(AltKeyCode.Mouse0, 0.1f);

    var pressingpoint2 = altDriver.FindObjectWhichContains(By.NAME, "PressingPoint2", cameraValue: "Player2");
    altDriver.MoveMouse(new AltVector2(pressingpoint2.x, pressingpoint2.y), 1);
    altDriver.PressKey(AltKeyCode.Mouse0, 0.1f);

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

PressKeys

Simulates multiple key press action in your app.

Parameters

PressKeys Parameters

Name

Type

Required

Default

Description

keycodes

List[AltKeyCode]

Yes

The list of keycodes simulated to be pressed simultaneously.

power

float

No

1

A value between [-1,1] used for joysticks to indicate how hard the buttons were pressed.

duration

float

No

0.1

The time measured in seconds from the multiple key press to the multiple key release.

wait

boolean

No

true

If set, waits for the command to finish.

Returns

  • Nothing

Examples

[Test]
public void TestPressKeys()
{
    AltKeyCode[] keys = { AltKeyCode.K, AltKeyCode.L };
    altDriver.PressKeys(keys);
    var altObject = altDriver.FindObject(By.NAME, "Capsule");
    var finalPropertyValue = altObject.GetComponentProperty<string>("AltExampleScriptCapsule", "stringToSetFromTests", "Assembly-CSharp");
    Assert.AreEqual("multiple keys pressed", finalPropertyValue);
}

Scroll

Simulate scroll action in your app.

Parameters

Scroll Parameters

Name

Type

Required

Default

Description

speed

float

No

1

Set how fast to scroll. Positive values will scroll up and negative values will scroll down.

duration

float

No

0.1

The duration of the scroll in seconds.

wait

boolean

No

true

If set, waits for the command to finish.

speedHorizontal

float

No

1

Set how fast to scroll right or left.

Returns

  • Nothing

Examples

[Test]
public void TestScroll()
{
    altDriver.LoadScene("Scene 5 Keyboard Input");
    var player2 = altDriver.FindObject(By.NAME, "Player2");
    AltVector3 cubeInitialPosition = new AltVector3(player2.worldX, player2.worldY, player2.worldY);
    altDriver.Scroll(4, 2);

    player2 = altDriver.FindObject(By.NAME, "Player2");
    AltVector3 cubeFinalPosition = new AltVector3(player2.worldX, player2.worldY, player2.worldY);
    Assert.AreNotEqual(cubeInitialPosition, cubeFinalPosition);
}

Swipe

Simulates a swipe action between two points.

Parameters

Swipe Parameters

Name

Type

Required

Default

Description

start

AltVector2

Yes

Starting location of the swipe.

end

AltVector2

Yes

Ending location of the swipe.

duration

float

No

0.1

The time measured in seconds to move the mouse from start to end location.

wait

boolean

No

true

If set, waits for the command to finish.

Returns

  • Nothing

Examples

[Test]
public void MultipleDragAndDrop()
{
    var altElement1 = altDriver.FindObject(By.NAME, "Drag Image1");
    var altElement2 = altDriver.FindObject(By.NAME, "Drop Box1");
    altDriver.Swipe(new AltVector2(altElement1.x, altElement1.y), new AltVector2(altElement2.x, altElement2.y), 1);

    altElement1 = altDriver.FindObject(By.NAME, "Drag Image2");
    altElement2 = altDriver.FindObject(By.NAME, "Drop Box2");
    altDriver.Swipe(new AltVector2(altElement1.x, altElement1.y), new AltVector2(altElement2.x, altElement2.y), 1);

    altElement1 = altDriver.FindObject(By.NAME, "Drag Image3");
    altElement2 = altDriver.FindObject(By.NAME, "Drop Box1");
    altDriver.Swipe(new AltVector2(altElement1.x, altElement1.y), new AltVector2(altElement2.x, altElement2.y), 1);

    altElement1 = altDriver.FindObject(By.NAME, "Drag Image1");
    altElement2 = altDriver.FindObject(By.NAME, "Drop Box1");
    altDriver.Swipe(new AltVector2(altElement1.x, altElement1.y), new AltVector2(altElement2.x, altElement2.y), 1);
    var imageSource = altDriver.FindObject(By.NAME, "Drag Image1").GetComponentProperty("UnityEngine.UI.Image", "sprite", "UnityEngine.UI");
    var imageSourceDropZone = altDriver.FindObject(By.NAME, "Drop Image").GetComponentProperty("UnityEngine.UI.Image", "sprite", "UnityEngine.UI");
    Assert.AreNotEqual(imageSource, imageSourceDropZone);

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

MultipointSwipe

Simulates a multipoint swipe action.

Parameters

MultiPointSwipe Parameters

Name

Type

Required

Default

Description

positions

List[AltVector2]

Yes

A list of positions on the screen where the swipe will be made.

duration

float

No

0.1

The time measured in seconds to swipe from the first position to the last position.

wait

boolean

No

true

If set, waits for the command to finish.

Returns

  • Nothing

Examples

[Test]
public void TestResizePanelWithMultipointSwipe()
{
    var altElement = altDriver.FindObject(By.NAME, "Resize Zone");
    var position = new AltVector2(altElement.x, altElement.y);
    var pos = new[]
    {
        altElement.GetScreenPosition(),
        new AltVector2(altElement.x - 200, altElement.y - 200),
        new AltVector2(altElement.x - 300, altElement.y - 100),
        new AltVector2(altElement.x - 50, altElement.y - 100),
        new AltVector2(altElement.x - 100, altElement.y - 100)
    };
    altDriver.MultipointSwipe(pos, 4);

    altElement = altDriver.FindObject(By.NAME, "Resize Zone");
    var position2 = new AltVector2(altElement.x, altElement.y);
    Assert.AreNotEqual(position, position2);
}

BeginTouch

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

Parameters

BeginTouch Parameters

Name

Type

Required

Description

coordinates

AltVector2

Yes

Screen coordinates.

Returns

  • int - the fingerId.

Examples

[Test]
public void TestNewTouchCommands()
{
    var draggableArea = altDriver.FindObject(By.NAME, "Drag Zone");
    var initialPosition = draggableArea.GetScreenPosition();
    int fingerId = altDriver.BeginTouch(draggableArea.GetScreenPosition());
    AltVector2 newPosition = new AltVector2(draggableArea.x + 20, draggableArea.y + 10);
    altDriver.MoveTouch(fingerId, newPosition);
    altDriver.EndTouch(fingerId);
    draggableArea = altDriver.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

MoveTouch Parameters

Name

Type

Required

Description

fingerId

int

Yes

Identifier returned by BeginTouch command.

coordinates

AltVector2

Yes

Screen coordinates where the touch will be moved.

Returns

  • Nothing

Examples

[Test]
public void TestNewTouchCommands()
{
    var draggableArea = altDriver.FindObject(By.NAME, "Drag Zone");
    var initialPosition = draggableArea.GetScreenPosition();
    int fingerId = altDriver.BeginTouch(draggableArea.GetScreenPosition());
    AltVector2 newPosition = new AltVector2(draggableArea.x + 20, draggableArea.y + 10);
    altDriver.MoveTouch(fingerId, newPosition);
    altDriver.EndTouch(fingerId);
    draggableArea = altDriver.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

EndTouch Parameters

Name

Type

Required

Description

fingerId

int

Yes

Identifier returned by BeginTouch command.

Returns

  • Nothing

Examples

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

Click

Click at screen coordinates.

Parameters

Click Parameters

Name

Type

Required

Default

Description

coordinates

AltVector2

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

If set, waits for the command to finish.

Returns

  • Nothing

Examples

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

Tap

Tap at screen coordinates.

Parameters

Tap Parameters

Name

Type

Required

Default

Description

coordinates

AltVector2

Yes

(empty)

The screen coordinates.

count

int

No

1

Number of taps.

interval

float

No

0.1

Interval between taps in seconds.

wait

boolean

No

true

If set, waits for the command to finish.

Returns

  • Nothing

Examples

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

Tilt

Simulates device rotation action in your app.

Parameters

Tilt Parameters

Name

Type

Required

Default

Description

acceleration

AltVector3

Yes

The linear acceleration of a device.

duration

float

No

0.1

How long the rotation will take in seconds.

wait

boolean

No

true

If set, waits for the command to finish.

Returns

  • Nothing

Examples

[Test]
public void TestAcceleration()
{
    var capsule = altDriver.FindObject(By.NAME, "Capsule");
    var initialWorldCoordinates = capsule.GetWorldPosition();
    altDriver.Tilt(new AltVector3(1, 1, 1), 1);
    Thread.Sleep(100);
    capsule = altDriver.FindObject(By.NAME, "Capsule");
    var afterTiltCoordinates = capsule.GetWorldPosition();
    Assert.AreNotEqual(initialWorldCoordinates, afterTiltCoordinates);
}

ResetInput

Clears all active input actions simulated by AltTester®.

Parameters

None

Returns

  • Nothing

Examples

 [Test]
public void TestResetInput()
{
    altDriver.KeyDown(AltKeyCode.P, 1);
    Assert.True(altDriver.FindObject(By.NAME, "AltTesterPrefab").GetComponentProperty<bool>("Altom.AltTester.NewInputSystem", "Keyboard.pKey.isPressed", "Assembly-CSharp"));
    altDriver.ResetInput();
    Assert.False(altDriver.FindObject(By.NAME, "AltTesterPrefab").GetComponentProperty<bool>("Altom.AltTester.NewInputSystem", "Keyboard.pKey.isPressed", "Assembly-CSharp"));

    int countKeyDown = altDriver.FindObject(By.NAME, "AltTesterPrefab").GetComponentProperty<int>("Input", "_keyCodesPressed.Count", "Assembly-CSharp");
    Assert.AreEqual(0, countKeyDown);
}

Screenshot

GetPNGScreenshot

Creates a screenshot of the current screen in png format.

Parameters

GetPNGScreenshot 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";
    altDriver.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:

PlayerPrefKeyType Assigned Value

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 retrieved

Returns

  • int

[Test]
public void TestDeleteKey()
{
    altDriver.DeletePlayerPref();
    altDriver.SetKeyPlayerPref("test", 1);
    var val = altDriver.GetIntKeyPlayerPref("test");
    Assert.AreEqual(1, val);
    altDriver.DeleteKeyPlayerPref("test");
    try
    {
        altDriver.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 retrieved

Returns

  • float

[Test]
public void TestDeleteKey()
{
    altDriver.DeletePlayerPref();
    altDriver.SetKeyPlayerPref("test", 1.0f);
    var val = altDriver.GetFloatKeyPlayerPref("test");
    Assert.AreEqual(1.0f, val);
    altDriver.DeleteKeyPlayerPref("test");
    try
    {
        altDriver.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 retrieved

Returns

  • string

[Test]
public void TestDeleteKey()
{
    altDriver.DeletePlayerPref();
    altDriver.SetKeyPlayerPref("test", "1");
    var val = altDriver.GetStringKeyPlayerPref("test");
    Assert.AreEqual("1", val);
    altDriver.DeleteKeyPlayerPref("test");
    try
    {
        altDriver.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()
{
    altDriver.DeletePlayerPref();
    altDriver.SetKeyPlayerPref("test", "1");
    var val = altDriver.GetStringKeyPlayerPref("test");
    Assert.AreEqual("1", val);
    altDriver.DeleteKeyPlayerPref("test");
    try
    {
        altDriver.GetStringKeyPlayerPref("test");
        Assert.Fail();
    }
    catch (NotFoundException exception)
    {
        Assert.AreEqual("notFound", exception.Message);
    }

}

DeleteKeyPlayerPref

Removes key and its corresponding value from PlayerPrefs.

Parameters

DeleteKeyPlayerPref Parameters

Name

Type

Required

Description

keyName

string

Yes

Key to be deleted.

Returns

  • Nothing

Examples

[Test]
public void TestDeleteKey()
{
    altDriver.DeletePlayerPref();
    altDriver.SetKeyPlayerPref("test", 1);
    var val = altDriver.GetIntKeyPlayerPref("test");
    Assert.AreEqual(1, val);
    altDriver.DeleteKeyPlayerPref("test");
    try
    {
        altDriver.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()
{
    altDriver.DeletePlayerPref();
    altDriver.SetKeyPlayerPref("test", 1);
    var val = altDriver.GetIntKeyPlayerPref("test");
    Assert.AreEqual(1, val);
}

GetCurrentScene

Returns the current active scene.

Parameters

None

Returns

  • String

Examples

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

LoadScene

Loads a scene.

Parameters

LoadScene Parameters

Name

Type

Required

Description

scene

string

Yes

The name of the scene to be loaded.

loadSingle

bool

No

If set to false, the scene will be loaded additive, together with the current loaded scenes. Default value is true.

Returns

  • Nothing

Examples

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

UnloadScene

Unloads a scene.

Parameters

UnloadScene Parameters

Name

Type

Required

Description

scene

string

Yes

Name of the scene to be unloaded.

Returns

  • Nothing

Examples

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

GetAllLoadedScenes

Returns all the scenes that have been loaded.

Parameters

None

Returns

  • List of strings

Examples

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

WaitForCurrentSceneToBe

Waits for the scene to be loaded for a specified amount of time.

Parameters

WaitForCurrentSceneToBe Parameters

Name

Type

Required

Description

sceneName

string

Yes

The name of the scene to wait for.

timeout

double

No

The time measured in seconds to wait for the specified scene.

interval

double

No

How often to check that the scene was loaded in the given timeout.

Returns

  • None

Examples

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

GetApplicationScreenSize

Returns the value of the application screen size.

Parameters

None

Returns

  • AltVector2

Examples

[Test]
public void TestGetApplicationScreenSize()
{
    altDriver.CallStaticMethod<string>("UnityEngine.Screen", "SetResolution", "UnityEngine.CoreModule", new string[] { "1920", "1080", "true" }, new string[] { "System.Int32", "System.Int32", "System.Boolean" });
    var screensize = altDriver.GetApplicationScreenSize();
    Assert.AreEqual(1920, screensize.x);
    Assert.AreEqual(1080, screensize.y);
}

GetTimeScale

Returns the value of the time scale.

Parameters

None

Returns

  • float

Examples

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

SetTimeScale

Sets the value of the time scale.

Parameters

SetTimeScale Parameters

Name

Type

Required

Description

timeScale

float

Yes

The value you want to set the time scale to.

Returns

  • Nothing

Examples

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

CallStaticMethod

Invokes static methods from your app.

Parameters

CallStaticMethod Parameters

Name

Type

Required

Description

typeName

string

Yes

The 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 to be called. If the method is inside a static property/field, use the format “propertyName.MethodName”.

assemblyName

string

Yes

The name of the assembly containing the script.

parameters

array

Yes

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.

Returns

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

Examples

[Test]
public void TestCallStaticMethod()
{

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

}

GetStaticProperty

Gets the value of the static field or property.

Parameters

GetStaticProperty 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.

assemblyName

string

Yes

The name of the assembly containing the component.

maxDepth

int

No

The maximum depth in the hierarchy to look for the static field or property. Default is 2.

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()
{
    altDriver.CallStaticMethod<string>("UnityEngine.Screen", "SetResolution", "UnityEngine.CoreModule", new string[] {"1920", "1080", "true"}, new string[] {"System.Int32", "System.Int32", "System.Boolean"});
    var width = altDriver.GetStaticProperty<int>("UnityEngine.Screen", "currentResolution.width", "UnityEngine.CoreModule");
    Assert.AreEqual(1920, width);
}

SetStaticProperty

Sets the value of the static field or property.

Parameters

SetStaticProperty Parameters

Name

Type

Required

Description

componentName

string

Yes

The name of the component. If the component has a namespace, the format should be “namespace.componentName”.

propertyName

string

Yes

The name of the property whose value you want to set.

assemblyName

string

Yes

The name of the assembly containing the component.

updatedProperty

object

Yes

The value to be set for the chosen component’s static property.

Returns

  • Nothing

Examples

[Test]
public void TestSetStaticProperty()
{
    var expectedValue = 5;
    altDriver.SetStaticProperty("AltExampleScriptCapsule", "privateStaticVariable", "Assembly-CSharp", expectedValue);
    var value = altDriver.GetStaticProperty<int>("AltExampleScriptCapsule", "privateStaticVariable", "Assembly-CSharp");
    Assert.AreEqual(expectedValue, value);
}

Other

SetServerLogging

Sets the level of logging on AltTester® Unity SDK.

Parameters

SetServerLogging Parameters

Name

Type

Description

logger

AltLogger

The type of logger.

logLevel

AltLogLevel

The logging level.

Returns

  • Nothing

Examples

altDriver.SetServerLogging(AltLogger.File, AltLogLevel.Off);
altDriver.SetServerLogging(AltLogger.Unity, AltLogLevel.Info);

AltObject

The AltObject class represents the objects present in the app 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

AltObject Fields

Name

Type

Description

name

string

The name of the object.

id

int

The object’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 app 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 app’s world.

worldY

float

The value for y axis coordinate in the app’s world.

worldZ

float

The value for z axis coordinate in the app’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:

FindObjectFromObject

Finds the first child of the object that respects the given criteria. Check By for more information about criteria.

Parameters

FindObjectFromObject 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 the object will be compared to see if it respects 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 coordinates of the object will be calculated. If no camera is given, it will search through all cameras in the scene until some camera sees the object or return the screen coordinates 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

Examples

[Test]
public void TestFindObjectFromObject()
{
    var parent = altDriver.FindObject(By.NAME,"Canvas");
    var child = parent.FindObjectFromObject(By.TEXT,"Change Camera Mode");
    Assert.AreEqual(child.name, "Text);
}

CallComponentMethod

Invokes a method from an existing component of the object.

Parameters

CallComponentMethod Parameters

Name

Type

Required

Description

componentName

string

Yes

The 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 needs to be the following format “propertyName.MethodName”.

assemblyName

string

Yes

The name of the assembly containing the component.

parameters

array

Yes

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.

Returns

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

Examples

[Test]
public void TestCallMethodWithAssembly()
{
    AltObject capsule = altDriver.FindObject(By.NAME, "Capsule");
    var initialRotation = capsule.GetComponentProperty<dynamic>("UnityEngine.Transform", "rotation", "UnityEngine.CoreModule");
    capsule.CallComponentMethod<string>("UnityEngine.Transform", "Rotate", "UnityEngine.CoreModule", new object[3] { 10, 10, 10 }, new[] { "System.Single", "System.Single", "System.Single" });
    AltObject capsuleAfterRotation = altDriver.FindObject(By.NAME, "Capsule");
    var finalRotation = capsuleAfterRotation.GetComponentProperty<dynamic>("UnityEngine.Transform", "rotation", "UnityEngine.CoreModule");
    Assert.IsTrue(initialRotation["x"] != finalRotation["x"] || initialRotation["y"] != finalRotation["y"] || initialRotation["z"] != finalRotation["z"] || initialRotation["w"] != finalRotation["w"]);
}

[Test]
public void TestCallMethodWithNoParameters()
{
    const string componentName = "UnityEngine.UI.Text";
    const string methodName = "get_text";
    const string assemblyName = "UnityEngine.UI";
    const string elementText = "Change Camera Mode";
    var altElement = altDriver.FindObject(By.PATH, "/Canvas/Button/Text");
    var data = altElement.CallComponentMethod<string>(componentName, methodName, assemblyName, new object[] { });
    Assert.AreEqual(elementText, data);
}

[Test]
public void TestCallMethodWithParameters()
{
    const string componentName = "UnityEngine.UI.Text";
    const string methodName = "set_fontSize";
    const string methodToVerifyName = "get_fontSize";
    const string assemblyName = "UnityEngine.UI";
    Int32 fontSizeExpected = 16;
    string[] parameters = new[] {"16"};
    var altElement = altDriver.FindObject(By.PATH, "/Canvas/UnityUIInputField/Text");
    var data = altElement.CallComponentMethod<string>(componentName, methodName, assemblyName, parameters);
    var fontSize =  altElement.CallComponentMethod<Int32>(componentName, methodToVerifyName, assemblyName, new object[] { });
    Assert.AreEqual(fontSizeExpected, fontSize);
}

WaitForComponentProperty

Wait until a property has a specific value and returns the value of the given component property.

Parameters

WaitForComponentProperty Parameters

Name

Type

Required

Description

componentName

string

Yes

The 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.

propertyValue

T

Yes

The value that the property should have.

assemblyName

string

Yes

The name of the assembly containing the component.

timeout

double

No

The number of seconds that it will wait for the property. The default value is 20 seconds.

interval

double

No

The number of seconds after which it will try to find the object again. The interval should be smaller than the timeout. The default value is 0.5 seconds.

getPropertyAsString

bool

No

If true, it will treat the propertyValue as a string; if false it will consider the original type of the propertyValue. This is especially useful when you want to pass for example [[], []] as a propertyValue, which you can do by setting getPropertyAsString to true and propertyValue to JToken.Parse(“[[], []]”) (in C#).

maxDepth

int

No

The value that defines the maximum level from which to retrieve properties. By default it is 2.

Returns

  • Object

Examples

[Test]
public void TestWaitForComponentProperty()
{
    const string componentName = "AltTester.AltTesterUnitySDK.Commands.AltRunner";
    const string propertyName = "InstrumentationSettings.AltServerPort";
    var altElement = altDriver.FindObject(By.NAME, "AltTesterPrefab");
    Assert.NotNull(altElement);

    string portStr = System.Environment.GetEnvironmentVariable("ALTSERVER_PORT");
    int port = int.Parse(portStr);
    var propertyValue = altElement.WaitForComponentProperty<int>(componentName, propertyName, port, "AltTester.AltTesterUnitySDK", maxDepth: 1);
    Assert.AreEqual(port, propertyValue);
}

[Test]
public void TestWaitForComponentPropertyAsString()
{
    var Canvas = altDriver.WaitForObject(By.PATH, "/Canvas");
    Canvas.WaitForComponentProperty("UnityEngine.Canvas", "transform", JToken.Parse("[[], [[]], [[]], [[]], [[]], [[], [], []], [[[], [], []]], [], [], [[]], [[]], [[]]]"), "UnityEngine.UIModule", 1, getPropertyAsString: true);
}

GetComponentProperty

Returns the value of the given component property.

Parameters

GetComponentProperty Parameters

Name

Type

Required

Description

componentName

string

Yes

The 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

Yes

The name of the assembly containing the component.

maxDepth

int

No

Set how deep the serialization of the property to do.

Returns

  • Object

Examples

[Test]
public void TestGetComponentProperty()
{
    const string componentName = "AltTester.AltTesterUnitySDK.Commands.AltRunner";
    const string propertyName = "InstrumentationSettings.AppName";
    var altElement = altDriver.FindObject(By.NAME, "AltTesterPrefab");
    Assert.NotNull(altElement);
    var propertyValue = altElement.GetComponentProperty<string>(componentName, propertyName, "AltTester.AltTesterUnitySDK");

    Assert.AreEqual("__default__", propertyValue);
}

SetComponentProperty

Sets value of the given component property.

Parameters

SetComponentProperty Parameters

Name

Type

Required

Description

componentName

string

Yes

The name of the component. If the component has a namespace, the format should look like this: “namespace.componentName”.

propertyName

string

Yes

The name of the property of which value you want to set.

value

object

Yes

The value to be set for the chosen component’s property.

assemblyName

string

Yes

The name of the assembly containing the component.

Returns

  • Nothing

Examples

[Test]
public void TestSetComponentProperty()
{
    const string componentName = "AltExampleScriptCapsule";
    const string propertyName = "stringToSetFromTests";
    var altElement = altDriver.FindObject(By.NAME, "Capsule");
    Assert.NotNull(altElement);
    altElement.SetComponentProperty(componentName, propertyName, "2", "Assembly-CSharp");

    var propertyValue = altElement.GetComponentProperty<string>(componentName, propertyName, "Assembly-CSharp");
    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 = altDriver.FindObject(By.NAME,name).GetText();
    var timeStart = DateTime.Now;
    var altObject = altDriver.WaitForObject(By.PATH, "//" + name + "[@text=" + text + "]");
    var timeEnd = DateTime.Now;
    var time = timeEnd - timeStart;
    Assert.Less(time.TotalSeconds, 20);
    Assert.NotNull(altObject);
    Assert.AreEqual(altObject.GetText(), text);

}

SetText

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

Parameters

SetText Parameters

Name

Type

Required

Default

Description

text

string

Yes

N/A

The text to be set.

submit

bool

No

N/A

If set will trigger a submit event.

Returns

Examples

[TestCase("UnityUIInputField")] // UI input field
[TestCase("TextMeshInputField")] // text mesh input field
public void TestSetTextForUnityUIInputField(string fieldName)
{
    var inputField = altDriver.FindObject(By.NAME, fieldName).SetText("exampleUnityUIInputField", true);
    Assert.AreEqual("exampleUnityUIInputField", inputField.GetText());
    Assert.IsTrue(inputField.GetComponentProperty<bool>("AltInputFieldRaisedEvents", "onValueChangedInvoked", "Assembly-CSharp"), "onValueChangedInvoked was false");
    Assert.IsTrue(inputField.GetComponentProperty<bool>("AltInputFieldRaisedEvents", "onSubmitInvoked", "Assembly-CSharp"), "onSubmitInvoked was false");
    Assert.IsTrue(inputField.GetComponentProperty<bool>("AltInputFieldRaisedEvents", "onEndEditInvoked", "Assembly-CSharp"), "onEndEditInvoked was false");
}

Tap

Tap current object.

Parameters

Tap 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

  • Nothing

Examples

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

Click

Click current object.

Parameters

Click 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

  • Nothing

Examples

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

PointerDown

Simulates pointer down action on the object.

Parameters

None

Returns

Examples

[Test]
public void TestPointerDown()
{
    altDriver.LoadScene("Scene 2 Draggable Panel");
    var panel = altDriver.FindObject(By.NAME, "Panel");
    var color1 = panel.GetComponentProperty<AltColor>("AltExampleScriptPanel", "normalColor", "Assembly-CSharp");
    panel.PointerDown();
    Thread.Sleep(1000);
    var color2 = panel.GetComponentProperty<AltColor>("AltExampleScriptPanel", "highlightColor", "Assembly-CSharp");
    Assert.AreNotEqual(color1, color2);
}

PointerUp

Simulates pointer up action on the object.

Parameters

None

Returns

Examples

[Test]
public void TestPointerUp()
{
    altDriver.LoadScene("Scene 2 Draggable Panel");
    var panel = altDriver.FindObject(By.NAME, "Panel");
    var color1 = panel.GetComponentProperty<AltColor>("AltExampleScriptPanel", "normalColor", "Assembly-CSharp");
    panel.PointerDown();
    Thread.Sleep(1000);
    panel.PointerUp();
    var color2 = panel.GetComponentProperty<AltColor>("AltExampleScriptPanel", "highlightColor", "Assembly-CSharp");
    Assert.AreEqual(color1, color2);
}

PointerEnter

Simulates pointer enter action on the object.

Parameters

None

Returns

Examples

[Test]
public void TestPointerEnterAndExit()
{
    altDriver.LoadScene("Scene 3 Drag And Drop");
    var altElement = altDriver.FindObject(By.NAME, "Drop Image");
    var color1 = altElement.GetComponentProperty<dynamic>("AltExampleScriptDropMe", "highlightColor", "Assembly-CSharp");
    altDriver.FindObject(By.NAME, "Drop Image").PointerEnter();
    var color2 = altElement.GetComponentProperty<dynamic>("AltExampleScriptDropMe", "highlightColor", "Assembly-CSharp");
    Assert.AreNotEqual(color1, color2);
    altDriver.FindObject(By.NAME, "Drop Image").PointerExit();
    var color3 = altElement.GetComponentProperty<dynamic>("AltExampleScriptDropMe", "highlightColor", "Assembly-CSharp");
    Assert.AreNotEqual(color3, color2);
    Assert.AreEqual(color1, color3);
}

PointerExit

Simulates pointer exit action on the object.

Parameters

None

Returns

Examples

[Test]
public void TestPointerEnterAndExit()
{
    altDriver.LoadScene("Scene 3 Drag And Drop");
    var altElement = altDriver.FindObject(By.NAME, "Drop Image");
    var color1 = altElement.GetComponentProperty<dynamic>("AltExampleScriptDropMe", "highlightColor", "Assembly-CSharp");
    altDriver.FindObject(By.NAME, "Drop Image").PointerEnter();
    var color2 = altElement.GetComponentProperty<dynamic>("AltExampleScriptDropMe", "highlightColor", "Assembly-CSharp");
    Assert.AreNotEqual(color1, color2);
    altDriver.FindObject(By.NAME, "Drop Image").PointerExit();
    var color3 = altElement.GetComponentProperty<dynamic>("AltExampleScriptDropMe", "highlightColor", "Assembly-CSharp");
    Assert.AreNotEqual(color3, color2);
    Assert.AreEqual(color1, color3);
}

UpdateObject

Returns the object with new values.

Parameters

None

Returns

Examples

[Test]
public void TestUpdateAltObject()
{
    var cube = altDriver.FindObject(By.NAME, "Player1");
    AltVector3 cubeInitialPostion = cube.GetWorldPosition();

    altDriver.PressKey(AltKeyCode.W, 1, 2);

    Assert.AreNotEqual(cubeInitialPostion, cube.UpdateObject().GetWorldPosition());
}

GetParent

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

Parameters

None

Returns

Examples

[Test]
public void TestGetParent()
{
    var altObject = altDriver.FindObject(By.NAME, "Panel", By.NAME, "Main Camera");
    var altObjectParent = altObject.GetParent();
    Assert.AreEqual("Panel Drag Area", altObjectParent.name);
}

GetScreenPosition

Returns the screen position of the AltTester® object.

Parameters

None

Returns

  • AltVector2

Examples

[Test]
public void TestHoldButton()
{
    const int duration = 1;
    var button = altDriver.FindObject(By.NAME, "UIButton");
    altDriver.HoldButton(button.GetScreenPosition(), duration);
    var capsuleInfo = altDriver.FindObject(By.NAME, "CapsuleInfo");
    var text = capsuleInfo.GetText();
    Assert.AreEqual(text, "UIButton clicked to jump capsule!");
    var time = float.Parse(altDriver.FindObject(By.NAME, "ChineseLetters").GetText());
    Assert.Greater(time, duration);
}

GetWorldPosition

Returns the world position of the AltTester® object.

Parameters

None

Returns

  • AltVector3

Examples

[Test]
public void TestAcceleration()
{
    var capsule = altDriver.FindObject(By.NAME, "Capsule");
    var initialWorldCoordinates = capsule.GetWorldPosition();
    altDriver.Tilt(new AltVector3(1, 1, 1), 1);
    Thread.Sleep(100);
    capsule = altDriver.FindObject(By.NAME, "Capsule");
    var afterTiltCoordinates = capsule.GetWorldPosition();
    Assert.AreNotEqual(initialWorldCoordinates, afterTiltCoordinates);
}

GetVisualElementProperty [Non-GPL]

Returns the value of the given property for a visual element.

Parameters

GetVisualElementProperty Parameters

Name

Type

Required

Description

propertyName

string

Yes

The name of the property for which you want to retrieve the value. The list of supported properties can be found in the Unity Documentation.

Returns

  • Object

Examples

[Test]
public void TestGetVisualElementProperty()
{
    var playButton = altDriver.FindObject(By.NAME, "Play");
    var width = playButton.GetVisualElementProperty<float>("width");
    Assert.That(width, Is.EqualTo(300));
}

WaitForVisualElementProperty [Non-GPL]

Waits for a visual element property to match a specified value.

Parameters

WaitForVisualElementProperty Parameters

Name

Type

Required

Description

propertyName

string

Yes

The name of the property to wait for. The list of supported properties can be found in the Unity Documentation.

propertyValue

T

Yes

The value to wait for the property to match.

timeout

number

No

The maximum time to wait for the property to match the value. Default is 20 seconds.

interval

number

No

The interval at which to check the property value. Default is 0.5 seconds.

getPropertyAsString

boolean

No

Whether to retrieve the property value as a string. Default is false.

Returns

  • Object: the value of the property once it matches the specified value.

Examples

[Test]
public void TestWaitForVisualElementProperty()
{
    var playButton = altDriver.FindObject(By.NAME, "Play");
    // Wait for the "width" property of a visual element to match 300f
    playButton.WaitForVisualElementProperty("width", 300f, 2, 0.5);
}

BY-Selector

It is used in find objects methods to set the criteria of which the objects are searched. Currently 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 object that respects the selectors. 0 - represents the first object, 1 - is the second object and so on. -1 -represents the last object

  • @tag

  • @layer

  • @name

  • @component

  • @id

  • @text

Examples

//NameOfParent/NameOfChild/*

//NameOfParent/NameOfChild//*

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

altDriver.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.

Examples

  • //Q&A - not escaped

  • //Q\\&A - escaped

AltId

Is a solution offered by AltTester® Unity SDK 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 app will have an AltId. Object instantiated during run time will not have an AltId

To add AltId to every object simply just click Add AltId to every object from AltTester® menu.

Add AltId

AltReversePortForwarding

API to interact with adb programmatically.

ReversePortForwardingAndroid

This method calls adb reverse [-s {deviceId}] tcp:{remotePort} tcp:{localPort}.

Parameters

ReversePortForwardingAndroid Parameters

Name

Type

Required

Description

remotePort

int

No

The device port to do reverse port forwarding from.

localPort

int

No

The local port to do reverse port forwarding 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 variable is not set, it tries to execute adb from PATH.

Examples

[OneTimeSetUp]
public void SetUp()
{
    AltReversePortForwarding.ReversePortForwardingAndroid();
    altDriver = new AltDriver();
}

Note: Sometimes, the execution of reverse port forwarding method is too slow so the tests fail because the port is not actually forwarded when trying to establish the connection. In order to fix this problem, a sleep() method should be called after calling the ReversePortForwardingAndroid() method.

RemoveReversePortForwardingAndroid

This method calls adb reverse --remove [-s {deviceId}] tcp:{devicePort} or adb reverse --remove-all if no port is provided.

Parameters

RemoveReversePortForwardingAndroid Parameters

Name

Type

Required

Description

devicePort

int

No

The device port to be removed.

deviceId

string

No

The id of the device to be removed.

adbPath

string

No

The adb path.

Returns

Nothing

Examples

[OneTimeTearDown]
public void TearDown()
{
    altDriver.Stop();
    AltReversePortForwarding.RemoveReversePortForwardingAndroid();
}

RemoveAllReversePortForwardingsAndroid

This method calls adb reverse --remove-all.

Parameters

RemoveAllReversePortForwardingsAndroid Parameters

Name

Type

Required

Description

adbPath

string

No

The adb path.

Returns

Nothing

Examples

[OneTimeTearDown]
public void TearDown()
{
    altDriver.Stop();
    AltReversePortForwarding.RemoveAllReversePortForwardingsAndroid();
}