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 |
|---|---|
Turns on a notification and calls your callback each time the app sends it. |
|
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 |
|---|---|---|---|
|
C#, Java, Python: |
required |
The notification to turn on: |
|
C#: |
required |
What to call with each notification. See the notification types below for what it receives. |
|
|
required (C#) |
|
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 |
|---|---|---|---|
|
C#, Java, Python: |
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 |
Java |
An |
Python, Robot Framework |
An object with |
Scene Unloaded (NotificationType.UNLOADSCENE)#
Sent each time the app unloads a scene.
Language |
The callback receives |
|---|---|
C# |
The scene name, a |
Java |
The scene name, a |
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 |
Java |
An |
Python, Robot Framework |
An object with |
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 |
Java |
A |
Python, Robot Framework |
|