Skip to content

Artifacts

What device.screenshot(), dump_hierarchy(), info(), driver_log(), capture() and stop_recording() return. Guide: Screenshots and artifacts.

Artifact

Something the device produced that a test may keep: a Screenshot, a Hierarchy, a DeviceInfo or a DriverLog. Every artifact is plain data with its serialized bytes and media_type, so it can go to a file (save), a report, an upload or an assertion without touching the device again.

Methods:

Name Description
save

Writes bytes to path (parent directories are created) and returns it.

media_type

media_type: str

The IANA media type of bytes, e.g. image/png.

extension

extension: str

The usual file extension for bytes, without the dot, e.g. png.

bytes

bytes: bytes

The serialized form: PNG, UTF-8 XML, UTF-8 JSON or UTF-8 text.

save

save(path: str | PathLike[str]) -> Path

Writes bytes to path (parent directories are created) and returns it.

Screenshot

Bases: Artifact

A screen capture (Device.screenshot()): the encoded image in format and its size in pixels.

format

format

width

width

height

height

bytes

bytes: bytes

media_type

media_type: str

extension

extension: str

ImageFormat

Bases: Enum

The encoding of a Screenshot's bytes.

PNG

PNG

media_type

media_type: str

extension

extension: str

Hierarchy

Bases: Artifact

The accessibility hierarchy as XML (Device.dump_hierarchy()). Diagnostic only: selectors never use it, so keep it out of assertions.

media_type

media_type

extension

extension

xml

xml

bytes

bytes: bytes

DeviceInfo

Bases: Artifact

Static facts about the device plus its current display, screen and focus state (Device.info()). Serialized as JSON.

api_level

api_level: int

manufacturer

manufacturer: str

model

model: str

product

product: str

display_width

display_width: int

display_height

display_height: int

display_rotation

display_rotation: DisplayRotation

current_package

current_package: str | None

The package owning the focused window, when there is one.

screen_on

screen_on: bool

The screen is on (interactive).

keyguard_locked

keyguard_locked: bool

The keyguard (lock screen) is showing.

keyguard_secure

keyguard_secure: bool

A PIN, pattern or password is set: Tap cannot dismiss this keyguard.

keyboard_shown

keyboard_shown: bool

A soft keyboard (any input method's window) is on screen.

auto_rotate

auto_rotate: bool

Auto-rotate is on: the sensor turns the display (off while a rotation is frozen).

animations_enabled

animations_enabled: bool

Window, transition or animator animations run (any of the three scales is not 0).

dark_mode

dark_mode: bool

The UI is in night mode (dark theme).

font_scale

font_scale: float

The font scale apps see (1.0 = the default size).

density_dpi

density_dpi: int

The display density apps see, in dpi.

airplane_mode

airplane_mode: bool

Airplane mode is on.

wifi_enabled

wifi_enabled: bool

Wi-Fi is switched on (also while airplane mode is on); says nothing about a connection.

mobile_data_enabled

mobile_data_enabled: bool

Mobile data is switched on; False on a device without telephony.

system_locales

system_locales: tuple[str, ...]

The device's languages, BCP-47 tags in preference order (Device.set_system_locales).

stay_awake

stay_awake: bool

The screen stays on while the device is plugged in (Device.set_stay_awake).

high_contrast_text

high_contrast_text: bool | None

High-contrast text is on; None when the driver cannot read it.

color_inversion

color_inversion: bool | None

Colour inversion is on; None when the driver cannot read it.

bold_text

bold_text: bool

The system font is bold (API 31+; always False below).

media_type

media_type

extension

extension

orientation

orientation: Orientation

PORTRAIT when the display is at least as tall as it is wide.

bytes

bytes: bytes

DriverLog

Bases: Artifact

The driver instrumentation's recent output (Device.driver_log()), one entry per line.

media_type

media_type

extension

extension

lines

lines

text

text: str

The lines joined with \n.

bytes

bytes: bytes

Recording

Bases: Artifact

An opt-in device recording: MP4 video, Matroska video+audio, or Opus audio.

Device.stop_recording() returns these verified bytes; save them wherever a test keeps its artifacts. A recording is never started implicitly on failure.

extension

extension

media_type

media_type

bytes

bytes: bytes

Encoded recording bytes.

Capture

The diagnostics of one device at one moment (Device.capture()): a Screenshot, the Hierarchy, the DeviceInfo and the DriverLog. A part is None when it could not be produced; failures says why, by part name.

Methods:

Name Description
save_to

Writes every produced part to directory as <prefix>.<name>.<extension> (for

SCREENSHOT

SCREENSHOT

HIERARCHY

HIERARCHY

DEVICE_INFO

DEVICE_INFO

DRIVER_LOG

DRIVER_LOG

serial

serial

screenshot

screenshot

hierarchy

hierarchy

info

info

driver_log

driver_log

failures

failures

Why each missing part is missing, keyed like artifacts.

artifacts

artifacts: dict[str, Artifact]

The parts that were produced, by name: screenshot, hierarchy, device-info, driver-log, in that order.

save_to

save_to(directory: str | PathLike[str], prefix: str | None = None) -> list[Path]

Writes every produced part to directory as <prefix>.<name>.<extension> (for example emulator-5554.screenshot.png; prefix defaults to the serial), creating directory, and returns the written paths.