Notifications#

Notifications tell your test about events in the app as they happen: a scene loads or unloads, the app logs a message, or the app is paused or resumed. Turn one on with AddNotificationListener and a NotificationType; the app then sends each such event to the driver, which calls your callback. Turn it off with RemoveNotificationListener. The notification types, and what each callback receives, are described below the commands.

Each command shows its signature and an example in every language; pick a language in any tab and the others switch with it.

Commands on this page#

Command

What it does

AddNotificationListener

Turns on a notification and calls your callback each time the app sends it.

RemoveNotificationListener

Turns off a notification and removes all the callbacks added for it.

AddNotificationListener#

Turns on a notification and calls your callback each time the app sends it. The driver calls the callback from its connection thread, while the test goes on.

void AddNotificationListener<T>(
    NotificationType notificationType,
    Action<T> callback,
    bool overwrite)

Example

// Print each scene the app loads while the test opens the next level.
altDriver.AddNotificationListener<AltLoadSceneNotificationResultParams>(
    NotificationType.LOADSCENE,
    result => Console.WriteLine($"Loaded {result.sceneName} ({result.loadSceneMode})"),
    true);
altDriver.LoadScene("Level2");
altDriver.RemoveNotificationListener(NotificationType.LOADSCENE);
void addNotification(AltAddNotificationListenerParams params)

new AltAddNotificationListenerParams.Builder(
    NotificationType notificationType,
    INotificationCallbacks callbacks)
    .Overwrite(boolean overwrite)  // default false
    .build()

Example

// Print each scene the app loads while the test opens the next level.
BaseNotificationCallbacks printScenes = new BaseNotificationCallbacks() {
    @Override
    public void SceneLoadedCallBack(AltLoadSceneNotificationResultParams result) {
        System.out.println(
                "Loaded " + result.sceneName + " (" + result.loadSceneMode + ")");
    }
};
altDriver.addNotification(new AltAddNotificationListenerParams.Builder(
        NotificationType.LOADSCENE, printScenes).Overwrite(true).build());
altDriver.loadScene(new AltLoadSceneParams.Builder("Level2").build());
altDriver.removeNotificationListener(new AltRemoveNotificationListenerParams.Builder(
        NotificationType.LOADSCENE).build());
alt_driver.add_notification_listener(
    notification_type,
    notification_callback,
    overwrite=True)

Example

from alttester.commands.Notifications import NotificationType


# Print each scene the app loads while the test opens the next level.
def print_scene(result):
    print(f"Loaded {result.scene_name} ({result.loadSceneMode})")


alt_driver.add_notification_listener(NotificationType.LOADSCENE, print_scene)
alt_driver.load_scene("Level2")
alt_driver.remove_notification_listener(NotificationType.LOADSCENE)
Add Notification Listener    notification_type    callback    overwrite=True

Example

*** Test Cases ***
Print Loaded Scenes
    # Print each scene the app loads while the test opens the next level.
    Add Notification Listener    LOADSCENE    Print Scene
    Load Scene    Level2
    Remove Notification Listener    LOADSCENE

*** Keywords ***
Print Scene
    [Arguments]    ${result}
    Log To Console    Loaded ${result.scene_name} (${result.loadSceneMode})

Parameters

Name

Type

Default

Description

notificationType (C#, Java)
notification_type (Python, Robot)

C#, Java, Python: NotificationType
Robot: name, such as LOADSCENE

required

The notification to turn on: LOADSCENE, UNLOADSCENE, LOG or APPLICATION_PAUSED.

callback (C#, Robot)
callbacks (Java)
notification_callback (Python)

C#: Action<T>
Java: INotificationCallbacks
Python: function
Robot: keyword name

required

What to call with each notification. See the notification types below for what it receives.

overwrite

bool

required (C#)
false (Java)
true (Python, Robot)

true replaces the callbacks already added for this notification type; false adds this one to them. In Java it’s the builder’s Overwrite(boolean).

Returns

Nothing.

Note

In C#, T is the type the callback receives: AltLoadSceneNotificationResultParams for LOADSCENE, string for UNLOADSCENE, AltLogNotificationResultParams for LOG and bool for APPLICATION_PAUSED. Any other type throws InvalidCastException.

In Java, the callback is an object that implements INotificationCallbacks. Extend BaseNotificationCallbacks and override the method of your notification, such as SceneLoadedCallBack; the methods you don’t override log the notification.

In Python, import the types with from alttester.commands.Notifications import NotificationType.

In Robot Framework, callback is the name of a keyword. It is run with the notification’s value as its one argument.

See also: RemoveNotificationListener

RemoveNotificationListener#

Turns off a notification and removes all the callbacks added for it.

void RemoveNotificationListener(NotificationType notificationType)

Example

// Print each scene the app loads while the test opens the next level.
altDriver.AddNotificationListener<AltLoadSceneNotificationResultParams>(
    NotificationType.LOADSCENE,
    result => Console.WriteLine($"Loaded {result.sceneName} ({result.loadSceneMode})"),
    true);
altDriver.LoadScene("Level2");
altDriver.RemoveNotificationListener(NotificationType.LOADSCENE);
void removeNotificationListener(
    AltRemoveNotificationListenerParams params)

new AltRemoveNotificationListenerParams.Builder(
    NotificationType notificationType)
    .build()

Example

// Print each scene the app loads while the test opens the next level.
BaseNotificationCallbacks printScenes = new BaseNotificationCallbacks() {
    @Override
    public void SceneLoadedCallBack(AltLoadSceneNotificationResultParams result) {
        System.out.println(
                "Loaded " + result.sceneName + " (" + result.loadSceneMode + ")");
    }
};
altDriver.addNotification(new AltAddNotificationListenerParams.Builder(
        NotificationType.LOADSCENE, printScenes).Overwrite(true).build());
altDriver.loadScene(new AltLoadSceneParams.Builder("Level2").build());
altDriver.removeNotificationListener(new AltRemoveNotificationListenerParams.Builder(
        NotificationType.LOADSCENE).build());
alt_driver.remove_notification_listener(notification_type)

Example

from alttester.commands.Notifications import NotificationType


# Print each scene the app loads while the test opens the next level.
def print_scene(result):
    print(f"Loaded {result.scene_name} ({result.loadSceneMode})")


alt_driver.add_notification_listener(NotificationType.LOADSCENE, print_scene)
alt_driver.load_scene("Level2")
alt_driver.remove_notification_listener(NotificationType.LOADSCENE)
Remove Notification Listener    notification_type

Example

*** Test Cases ***
Print Loaded Scenes
    # Print each scene the app loads while the test opens the next level.
    Add Notification Listener    LOADSCENE    Print Scene
    Load Scene    Level2
    Remove Notification Listener    LOADSCENE

*** Keywords ***
Print Scene
    [Arguments]    ${result}
    Log To Console    Loaded ${result.scene_name} (${result.loadSceneMode})

Parameters

Name

Type

Default

Description

notificationType (C#, Java)
notification_type (Python, Robot)

C#, Java, Python: NotificationType
Robot: name, such as LOADSCENE

required

The notification to turn off.

Returns

Nothing.

See also: AddNotificationListener

Scene Loaded (NotificationType.LOADSCENE)#

Sent each time the app loads a scene.

Language

The callback receives

C#

An AltLoadSceneNotificationResultParams, with sceneName and loadSceneMode (AltLoadSceneMode.Single or Additive).

Java

An AltLoadSceneNotificationResultParams in SceneLoadedCallBack, with sceneName and loadSceneMode (LoadSceneMode.SINGLE or ADDITIVE).

Python, Robot Framework

An object with scene_name and loadSceneMode (LoadSceneMode.Single or Additive).

Scene Unloaded (NotificationType.UNLOADSCENE)#

Sent each time the app unloads a scene.

Language

The callback receives

C#

The scene name, a string.

Java

The scene name, a String, in SceneUnloadedCallBack.

Python, Robot Framework

The scene name.

Log Notification (NotificationType.LOG)#

Sent each time the app logs a message with Unity’s Debug.Log and related methods. The level is Error for errors and exceptions, Warn for warnings, and Debug for any other message, including asserts.

Language

The callback receives

C#

An AltLogNotificationResultParams, with message, stackTrace and level, an AltLogLevel.

Java

An AltLogNotificationResultParams in LogCallBack, with message, stackTrace and level, a number: AltLogLevel.values()[level] gives its name.

Python, Robot Framework

An object with message, stack_trace and type, the level as a number (1 Debug, 3 Warn, 4 Error). In 2.4.1, stack_trace is always None.

Application Paused (NotificationType.APPLICATION_PAUSED)#

Sent each time the app is paused or resumed, such as when a mobile app goes to the background and comes back. If the app is already paused when you turn the notification on, it is sent at once.

Language

The callback receives

C#

A bool: true when the app is paused, false when it resumes.

Java

A boolean in ApplicationPausedCallBack: true when the app is paused, false when it resumes.

Python, Robot Framework

True when the app is paused, False when it resumes.