BiDi Commands and Events
The XCUITest driver has partial support of the WebDriver BiDi Protocol. It inherits the BiDi commands and events supported by the Appium base driver, and additionally defines the events and commands listed below.
Events¶
log.entryAdded¶
WebDriver BiDi documentation: log.entryAdded
Indicates that a new log entry is available for consumption.
This event is emitted when the driver retrieves a new entry for any of the log types listed below.
Log capture can also be disabled using the appium:skipLogCapture capability.
Event Type (CDDL)¶
log.entryAded = (
context: text,
method: "log.entryAdded",
params: {
type: text,
level: "debug" / "info" / "warn" / "error",
source: {
realm: '',
context: text,
},
text: text,
timestamp: js-uint,
},
)
| Parameter | Description |
|---|---|
context |
The context in which the log was created, usually either native or webview |
type |
One of the supported log types listed below |
text |
Contents of the log entry |
timestamp |
Timestamp of the log entry |
Supported Types¶
Event emission of all of these log types is supported for both real devices and emulators.
crashlog- Each event contains a particular device crash report entry
contextis always set toNATIVE_APP- Real devices must have iOS/tvOS 18 or later, and the
appium-ios-remotexpcpackage must be installed. Refer to the RemoteXPC Tunnels guide for more details.
syslog- Each event contains a single device system log line
contextis always set toNATIVE_APPlevelis derived from the severity of the line, and falls back toinfoif it cannot be determined
safariConsole- Each event contains a single Safari console log line
contextis always set to the appropriate web context name- Events are only emitted if the
appium:showSafariConsoleLogcapability is set
safariNetwork- Each event contains a single Safari network log line
contextis always set to the appropriate web context name- Events are only emitted if the
appium:showSafariNetworkLogcapability is set
performance- Each event contains a single Safari performance log line
contextis always set to the appropriate web context name- Events are only emitted if the
appium:enablePerformanceLoggingcapability is set
server- Each event contains a single Appium server log line
contextis always set toNATIVE_APP- Events are only emitted if the
get_server_logsinsecure feature is enabled
Usage¶
Start the session with the webSocketUrl capability set to true and subscribe to the log.entryAdded event
(or to the whole log module). The driver only emits the event while a client is subscribed to it.
Subscriptions may be scoped to contexts. The safariConsole, safariNetwork and performance events are
reported with the name of the webview context they come from, e.g. WEBVIEW_5191.1, and all the other
types with NATIVE_APP. Omit the contexts to receive the events of all of them.
The safariConsole and safariNetwork events received while switching between webviews may be attributed
to the destination webview.
The events arrive over the BiDi connection of the session, so there is no need
for direct access to the host and port of the Appium server.
// Requires the java-client-selenium-bridge artifact, see
// https://github.com/appium/java-client/blob/master/docs/selenium-bridge.md
var driver = new IOSDriver(serverUrl, options.enableBiDi());
var selenium = SeleniumBridge.asRemoteWebDriver(driver);
try (var logInspector = new LogInspector(selenium)) {
logInspector.onLog(entry -> System.out.println(entry.getText()));
// ... run the test
} finally {
selenium.closeBiDi();
}
appium:xcuitest.contextUpdated¶
Indicates a change in the current Appium context.
This event is emitted upon context change, either explicit or implicit. It is also emitted at the start of a new session.
See the GitHub feature ticket for more details.
Event Type (CDDL)¶
appium:xcuitest.contextUpdated = (
method: "appium:xcuitest.contextUpdated",
params: {
name: text,
type: "NATIVE" / "WEB",
},
)
| Parameter | Description |
|---|---|
name |
The name of the new context |
type |
The type of the currently active context. Supported values are NATIVE or WEB. |
appium:mediaStream.started¶
Indicates that a stream started by mobile: startMediaStream
is producing output. All the appium:mediaStream.* events are only emitted while a client is subscribed
to the event or to the whole appium:mediaStream module. They are not emitted at all for a stream that
fails to start.
A video stream sends this event when the encoder produces its first keyframe, just before the execute method returns. A JPEG stream sends it right after it starts.
appium:mediaStream.started = (
context: text,
method: "appium:mediaStream.started",
params: {
streamId: text,
kind: "video" / "jpeg",
tracks: [+ ("video" / "audio" / "jpeg")],
codec: "h264" / "hevc" / "jpeg",
event: "appium:mediaStream",
? width: js-uint,
? height: js-uint,
? audio: {sampleRate: js-uint, channels: js-uint},
},
)
appium:mediaStream.units¶
Carries the media data of a stream.
appium:mediaStream.units = (
context: text,
method: "appium:mediaStream.units",
params: {
streamId: text,
units: [+ {
track: "video" / "audio" / "jpeg",
seq: js-uint,
ts: js-uint,
key: bool,
data: text,
}],
dropped: js-uint,
},
)
| Parameter | Description |
|---|---|
track |
video, audio or jpeg. Each event holds units of a single track. |
seq |
Sequence number of the unit, counted per track |
ts |
Timestamp in microseconds, on one clock shared by all the tracks of a stream |
key |
Whether this is a video keyframe. Always true for audio and JPEG units |
data |
Base64-encoded data of the unit |
dropped |
The number of units that were skipped for a slow client before this event. It is advisory. |
Video units are Annex-B H.264/HEVC. The codec configuration (SPS/PPS/VPS) is part of every keyframe, so a client can start decoding at any keyframe. A keyframe always starts a new event. Audio units are ADTS AAC-LC frames (48 kHz, stereo on Simulators), and a JPEG unit is a complete frame.
Video units are held back until a keyframe arrives after the subscription started. If a client cannot keep up with the stream, Appium skips video units until the next keyframe and delivers audio units reliably.
appium:mediaStream.formatChanged¶
Indicates that the frame size of a stream has changed. For a video stream this happens after the Simulator
rotates, and the events with the units of the previous size are always delivered before it. A JPEG stream
sends it with the first frame and whenever the size changes. The width and height are omitted if the size
is not known.
appium:mediaStream.formatChanged = (
context: text,
method: "appium:mediaStream.formatChanged",
params: {
streamId: text,
? width: js-uint,
? height: js-uint,
},
)
appium:mediaStream.ended¶
Indicates that a stream has ended, for any reason.
appium:mediaStream.ended = (
context: text,
method: "appium:mediaStream.ended",
params: {
streamId: text,
reason: text,
},
)
The reason is stopped if the stream was stopped by mobile: stopMediaStream,
ended if the source ended the stream, or error: <message>. Appium closes the BiDi connection when the session is deleted, so the event is not delivered then.
appium:xcuitest.networkMonitor¶
Indicates that a new network event is available for consumption.
This event is continuously emitted as soon as the mobile: startNetworkMonitor is invoked. Event emission stops as soon as the mobile: stopNetworkMonitor
execute method is called, or when the stream ends on its own (for example if the device connection drops).
No event announces the latter, so call mobile: startNetworkMonitor again to resume.
Events are only supported for real devices running iOS/tvOS 18 or later, and the
appium-ios-remotexpc package must be installed. Refer to the RemoteXPC Tunnels guide
for more details.
Event Type (CDDL)¶
There are 3 types of supported network events, each of which has its own shape. Event shapes match
the NetworkEvent types used in appium-ios-remotexpc.
appium:xcuitest.networkMonitor = (
method: "appium:xcuitest.networkMonitor",
context: "NATIVE_APP",
params: {
event: {
appium:xcuitest.networkMonitor.InterfaceDetectionEntry /
appium:xcuitest.networkMonitor.ConnectionDetectionEntry /
appium:xcuitest.networkMonitor.ConnectionUpdateEntry
},
},
)
All event entries include the type field, which is used to distinguish them:
| Type | Name |
Meaning |
|---|---|---|
0 |
Interface detection | An interface appeared or was reported (index + kernel name). |
1 |
Connection detection | A local/remote socket pair was observed (addresses, PID, interface, serial). |
2 |
Connection update | Counters and RTT for an existing flow; correlate with detection via connectionSerial. |
Interface Detection Event¶
appium:xcuitest.networkMonitor.InterfaceDetectionEntry = {
type: 0,
interfaceIndex: js-uint,
name: text,
}
| Parameter | Description |
|---|---|
interfaceIndex |
Interface index |
name |
Interface name |
Connection Detection Event¶
appium:xcuitest.networkMonitor.ConnectionDetectionEntry = {
type: 1,
localAddress: appium:xcuitest.networkMonitor.NetworkAddress,
remoteAddress: appium:xcuitest.networkMonitor.NetworkAddress,
interfaceIndex: js-uint,
pid: js-uint,
recvBufferSize: js-uint,
recvBufferUsed: js-uint,
serialNumber: js-uint,
kind: js-uint,
}
| Parameter | Description |
|---|---|
localAddress |
Local address information |
remoteAddress |
Remote address information |
interfaceIndex |
Interface index |
pid |
ID of the process owning the connection |
recvBufferSize |
Receive buffer size |
recvBufferUsed |
Receive buffer used |
serialNumber |
Connection serial number |
kind |
Connection kind/type |
appium:xcuitest.networkMonitor.NetworkAddress = {
len: js-uint,
family: js-uint,
port: js-uint,
address: text,
flowInfo: js-uint,
scopeId: js-uint,
}
| Parameter | Description |
|---|---|
len |
Length of the address structure |
family |
Address family |
port |
Port number |
address |
Parsed IP address string |
flowInfo |
Flow info (IPv6 only) |
scopeId |
Scope ID (IPv6 only) |
IPv4/IPv6 addresses are normalized strings; family is the raw sockaddr family (e.g. 2 = IPv4,
30 = IPv6).
Connection Update Event¶
appium:xcuitest.networkMonitor.ConnectionUpdateEntry = {
type: js-uint,
rxPackets: js-uint,
rxBytes: js-uint,
txPackets: js-uint,
txBytes: js-uint,
rxDups: js-uint,
rx000: js-uint,
txRetx: js-uint,
minRtt: js-uint,
avgRtt: js-uint,
connectionSerial: js-uint,
time: js-uint,
}
| Parameter | Description |
|---|---|
rxPackets |
Number of received packets |
rxBytes |
Number of received bytes |
txPackets |
Number of transmitted packets |
txBytes |
Number of transmitted bytes |
rxDups |
Number of duplicate received packets |
rx000 |
Reserved field |
txRetx |
Number of retransmitted packets |
minRtt |
Minimum round-trip time |
avgRtt |
Average round-trip time |
connectionSerial |
Connection serial number |
time |
Timestamp |
You can use the value of connectionSerial to link back to a prior type: 1 event with a matching
serialNumber value.
appium:xcuitest.systemMonitor¶
Indicates that a new labelled DVT sysmontap sample (system-wide or per-process) is available for consumption.
This event is continuously emitted as soon as mobile: startSystemMonitor is invoked. Event emission stops as soon as the mobile: stopSystemMonitor
execute method is called, or when the stream ends on its own (for example if the device connection drops).
No event announces the latter, so call mobile: startSystemMonitor again to resume.
Events are only supported for real devices running iOS/tvOS 18 or later, and the
appium-ios-remotexpc package must be installed. Refer to the
RemoteXPC Tunnels guide for more details.
Event Type (CDDL)¶
The device streams two kinds of samples, discriminated by event.kind. The attribute set for
each kind is queried from the device at connection time, so the exact fields present can vary
slightly across OS versions. Refer to
the Sysmontap instrument used in appium-ios-remotexpc
for the labelling logic.
appium:xcuitest.systemMonitor = (
method: "appium:xcuitest.systemMonitor",
context: "NATIVE_APP",
params: {
event: appium:xcuitest.systemMonitor.SystemEntry / appium:xcuitest.systemMonitor.ProcessesEntry,
},
)
appium:xcuitest.systemMonitor.SystemEntry = {
kind: "system",
system: {
* text => any,
},
}
appium:xcuitest.systemMonitor.ProcessesEntry = {
kind: "processes",
processes: [* appium:xcuitest.systemMonitor.ProcessInfo],
}
appium:xcuitest.systemMonitor.ProcessInfo = {
pid: js-uint,
? name: text,
? cpuUsage: number,
? physFootprint: js-uint,
* text => any,
}
| Parameter | Description |
|---|---|
kind |
Discriminates the sample: "system" for a device-wide snapshot, "processes" for a per-process snapshot array |
system |
Device-wide metrics, keyed by the system attribute names reported by the device (e.g. total CPU usage, memory size) |
processes |
One entry per process observed in this sample |
pid |
Process ID (also included as an attribute if the device reports one; the attribute value takes precedence) |
name |
Process name, when reported |
cpuUsage |
Per-process CPU usage, when reported |
physFootprint |
Per-process physical memory footprint in bytes, when reported |
The first processes snapshot after starting the monitor typically has uninitialised cpuUsage
values (there is no prior sample to diff against) and is commonly ignored by consumers.