API

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

Important

Since we are using the same driver for both AltTester® Unreal SDK and AltTester® Unity SDK, certain features or methods might appear in code editors (e.g., Visual Studio Code) due to shared APIs but are not included in this documentation because they are not supported or relevant for the current platform. We recommend consulting the documentation for the latest platform-specific updates and verifying feature availability in your project.

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 Unreal application. In the constructor, we need to tell the driver where (on what IP and on what port) the instrumented Unreal 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® Unreal 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 Unreal 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 Unreal application. The default value is: unknown

platformVersion

string

No

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

deviceInstanceId

string

No

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

appId

string

No

The unique ID of the Unreal 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 level that respects the given criteria. Check By for more information about criteria.

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.

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 level that respects the given criteria. Check By for more information about criteria.

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.

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 level that respects the given criteria. Check By for more information about criteria.

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.

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 level that respects the given criteria. Check By for more information about criteria.

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.

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 Unreal object at given coordinates.

Uses WorldContext->LineTraceSingleByChannel with ECC_Visibility to perform a line trace from the start to the end point. If no object is found at the given location, the trace will return an empty result.

Parameters

FindObjectAtCoordinates Parameters

Name

Type

Required

Description

coordinates

AltVector2

Yes

The screen coordinates.

Returns

  • AltObject - The object hit by LineTraceSingleByChannel, 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 levels.

Parameters

GetAllElements Parameters

Name

Type

Required

Description

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.

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.

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.

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.

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 level that respects the given criteria is no longer in the level or until the timeout limit is reached. Check By for more information about criteria.

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.

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);

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.

Returns

  • Nothing

Examples

[Test]
public void TestKeyDownAndKeyUp()
{
    AltKeyCode kcode = AltKeyCode.A;
    altDriver.KeyDown(kcode);

    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()
{
    AltKeyCode kcode = AltKeyCode.A;
    altDriver.KeyDown(kcode);

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

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.

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 TestPressLeftArrow()
{
    AltKeyCode kcode = AltKeyCode.LeftArrow;
    altDriver.PressKey(kcode);
}

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.

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

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!"]");
}

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

Other Commands

GetCurrentScene

Returns the name of the currently loaded level.

Parameters

None

Returns

  • String

Examples

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

LoadScene

Loads a level by its name.

Parameters

LoadScene Parameters

Name

Type

Required

Description

scene

string

Yes

The name of the level to be loaded.

loadSingle

bool

No

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

Returns

  • Nothing

Examples

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

WaitForCurrentSceneToBe

Waits for the specified level to be loaded within a given amount of time.

Parameters

WaitForCurrentSceneToBe Parameters

Name

Type

Required

Description

sceneName

string

Yes

The name of the level to wait for.

timeout

double

No

The time measured in seconds to wait for the specified level to load.

interval

double

No

How often, in seconds, to check that the level was loaded.

Returns

  • None

Examples

[Test]
public void TestWaitForCurrentSceneToBe()
{
    const string name = "MainMenu";
    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("MainMenu", currentScene);
}

GetApplicationScreenSize

Retrieves the viewport size of the application.

Parameters

None

Returns

  • AltVector2

Examples

[Test]
public void TestGetApplicationScreenSize()
{
    var screensize = altDriver.GetApplicationScreenSize();
    Assert.AreEqual(1920, screensize.x);
    Assert.AreEqual(1080, screensize.y);
}

GetTimeScale

Retrieves the current global time dilation value using UGameplayStatics::GetGlobalTimeDilation.

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 global time dilation to the specified value using UGameplayStatics::SetGlobalTimeDilation.

Parameters

SetTimeScale Parameters

Name

Type

Required

Description

timeScale

float

Yes

The value you want to set the global time dilation.

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 class blueprint or C++ class.

methodName

string

Yes

The name of the method that we want to call.

assemblyName

string

Yes

parameters

array

Yes

An array containing the serialized parameters, formatted as strings, 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.

Important

Since we are using the same driver for both AltTester® Unreal SDK and AltTester® Unity SDK, the assemblyName is required but can be set to an empty string in Unreal SDK.

Returns

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

Examples

[Test]
public void TestCallStaticMethod()
{
    var screenResolution = altDriver.CallStaticMethod<string>("GameUserSettings", "GetScreenResolution", "", []);

    var match = Regex.Match(screenResolution, @"X=(\d+),Y=(\d+)");
    int screenWidth = int.Parse(match.Groups[1].Value);
    int screenHeight = int.Parse(match.Groups[2].Value);

    Assert.Multiple(() =>
    {
        Assert.That(1920, Is.EqualTo(screenWidth));
        Assert.That(1080, Is.EqualTo(screenHeight));
    });
}

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.

type

string

Object’s type, this field corresponds to the object’s class name.

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.

transformId

int

The transform’s component id.

transformParentId

int

The transform parent’s id.

Important

In the AltTester® Unreal SDK, the transformId field is the same as the id field.

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.

methodName

string

Yes

The name of the method (public or private) that will be called.

assemblyName

string

Yes

parameters

array

Yes

An array containing the serialized parameters, formatted as strings, 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.

Important

Since we are using the same driver for both AltTester® Unreal SDK and AltTester® Unity SDK, the assemblyName is required but can be set to an empty string in Unreal SDK.

Returns

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

Examples

[Test]
public void TestCallMethodWithNoParameters()
{
    const string componentName = "Actor";
    const string methodName = "K2_GetActorRotation";
    const string assemblyName = "";

    var player = altDriver.FindObject(By.NAME, "Hero");
    string playerRotation = player.CallComponentMethod<string>(componentName, methodName, assemblyName, []);
    Assert.That(playerRotation, Is.EqualTo("(Pitch=0.000000,Yaw=90.000000,Roll=0.000000)"));
}

[Test]
public void TestCallMethodWithParameters()
{
    const string componentName = "Controller";
    const string methodName = "SetControlRotation";
    const string assemblyName = "";
    const string playerRotation = "(Pitch=0.000000,Yaw=180.000000,Roll=0.000000)";

    var player = altDriver.FindObject(By.NAME, "Hero");
    player.CallComponentMethod<string>(componentName, methodName, assemblyName, [playerRotation]);
}

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.

propertyName

string

Yes

Name of the property of which value you want.

propertyValue

T

Yes

The value that the property should have.

assemblyName

string

Yes

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#).

Important

Since we are using the same driver for both AltTester® Unreal SDK and AltTester® Unity SDK, the assemblyName is required but can be set to an empty string in Unreal SDK.

Returns

  • Object

Examples

[Test]
public void TestWaitForComponentProperty()
{
    const string componentName = "AltExampleScriptCapsule";
    const string propertyName = "TestBool";

    var altElement = altDriver.FindObject(By.NAME, "Capsule");
    var result = altElement.WaitForComponentProperty<bool>(componentName, propertyName, true, "");
    Assert.IsTrue(result);
}

GetComponentProperty

Returns the value of the given component property.

Parameters

GetComponentProperty Parameters

Name

Type

Required

Description

componentName

string

Yes

The name of the component.

propertyName

string

Yes

Name of the property of which value you want.

assemblyName

string

Yes

Important

Since we are using the same driver for both AltTester® Unreal SDK and AltTester® Unity SDK, the assemblyName is required but can be set to an empty string in Unreal SDK.

Returns

  • Object

Examples

[Test]
public void TestGetComponentProperty()
{
    var player = altDriver.FindObject(By.NAME, "Hero");

    var capsuleHalfHeight = player.GetComponentProperty<float>("CapsuleComponent", "CapsuleHalfHeight", "");
    Assert.AreEqual(65f, capsuleHalfHeight);
}

SetComponentProperty

Sets value of the given component property.

Parameters

SetComponentProperty Parameters

Name

Type

Required

Description

componentName

string

Yes

The name of the component.

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

Important

Since we are using the same driver for both AltTester® Unreal SDK and AltTester® Unity SDK, the assemblyName is required but can be set to an empty string in Unreal SDK.

Returns

  • Nothing

Examples

[Test]
public void TestSetComponentProperty()
{
    const string componentName = "AltExampleScriptCapsule";
    const string propertyName = "stringToSetFromTests";

    var altElement = altDriver.FindObject(By.NAME, "BP_Capsule");
    Assert.That(altElement, Is.Not.Null);
    altElement.SetComponentProperty(componentName, propertyName, "2", "");

    var propertyValue = altElement.GetComponentProperty<string>(componentName, propertyName, "");
    Assert.That(propertyValue, Is.EqualTo("2"));
}

GetText

Returns text value from a TextBlock, EditableText, EditableTextBox.

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 TextBlock, EditableText, EditableTextBox.

Parameters

SetText Parameters

Name

Type

Required

Default

Description

text

string

Yes

N/A

The text to be set.

Returns

Examples

public void TestSetText(string fieldName)
{
    string fieldName = "UnrealUIInputField";
    string text = "exampleUnrealUIInputField";
    
    AltObject inputField = altDriver.FindObject(By.NAME, fieldName).SetText(text);
    Assert.That(inputField.UpdateObject().GetText(), Is.EqualTo(text));
}

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]");
}

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);
    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");
    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 TestGetScreenPosition()
{
    AltObject altObject = altDriver.FindObject(By.PATH, "//Plane");
    var screenPosition = altObject.GetScreenPosition();

    AltObject element = altDriver.FindObjectAtCoordinates(screenPosition);
    Assert.That(element, Is.Not.Null);
    Assert.That(element.name, Does.Match(@"^StaticMeshActor_\d+$"));
}

GetWorldPosition

Returns the world position of the AltTester® object.

Parameters

None

Returns

  • AltVector3

Examples

[Test]
public void TestGetWorldPosition()
{
    var capsule = altDriver.FindObject(By.NAME, "Capsule");
    var worldCoordinates = capsule.GetWorldPosition();

    var expectedCoordinates = new AltVector3(0, 0, 0);
    Assert.AreEqual(expectedCoordinates, worldCoordinates);
}

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 actor 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)

  • 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

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

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

Returns

Nothing

Examples

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