# Artifacts

What `device.screenshot()`, `dump_hierarchy()`, `info()`, `driver_log()`, `capture()` and
`stop_recording()` return. Guide: [Screenshots and artifacts](../../guide/artifacts.md).

## <kbd>class</kbd> `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. 

---

#### <kbd>property</kbd> Artifact.bytes

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

---

### <kbd>method</kbd> `Artifact.save`

```python
save(path: 'str | os.PathLike[str]') → pathlib.Path
```

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

## <kbd>class</kbd> `Screenshot`
A screen capture (``Device.screenshot()``): the encoded image in ``format`` and its size in pixels. 

### <kbd>method</kbd> `Screenshot.__init__`

```python
__init__(
    data: 'builtins.bytes',
    format: 'ImageFormat',
    width: 'int',
    height: 'int'
)
```

---

#### <kbd>property</kbd> Screenshot.bytes

---

#### <kbd>property</kbd> Screenshot.extension

---

#### <kbd>property</kbd> Screenshot.media_type

---

### <kbd>method</kbd> `Screenshot.save`

```python
save(path: 'str | os.PathLike[str]') → pathlib.Path
```

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

## <kbd>class</kbd> `ImageFormat`
The encoding of a ``Screenshot``'s bytes. 

## <kbd>class</kbd> `Hierarchy`
The accessibility hierarchy as XML (``Device.dump_hierarchy()``). Diagnostic only: selectors never use it, so keep it out of assertions. 

### <kbd>method</kbd> `Hierarchy.__init__`

```python
__init__(xml: 'str')
```

---

#### <kbd>property</kbd> Hierarchy.bytes

---

### <kbd>method</kbd> `Hierarchy.save`

```python
save(path: 'str | os.PathLike[str]') → pathlib.Path
```

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

## <kbd>class</kbd> `DeviceInfo`
Static facts about the device plus its current display, screen and focus state (``Device.info()``). Serialized as JSON. 

### <kbd>method</kbd> `DeviceInfo.__init__`

```python
__init__(
    api_level: 'int',
    manufacturer: 'str',
    model: 'str',
    product: 'str',
    display_width: 'int',
    display_height: 'int',
    display_rotation: 'DisplayRotation',
    current_package: 'str | None',
    screen_on: 'bool',
    keyguard_locked: 'bool',
    keyguard_secure: 'bool',
    keyboard_shown: 'bool',
    auto_rotate: 'bool',
    animations_enabled: 'bool',
    dark_mode: 'bool',
    font_scale: 'float',
    density_dpi: 'int',
    airplane_mode: 'bool',
    wifi_enabled: 'bool',
    mobile_data_enabled: 'bool',
    system_locales: 'tuple[str, ...]' = (),
    stay_awake: 'bool' = False,
    high_contrast_text: 'bool | None' = None,
    color_inversion: 'bool | None' = None,
    bold_text: 'bool' = False
) → None
```

---

#### <kbd>property</kbd> DeviceInfo.bytes

---

#### <kbd>property</kbd> DeviceInfo.orientation

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

---

### <kbd>method</kbd> `DeviceInfo.save`

```python
save(path: 'str | os.PathLike[str]') → pathlib.Path
```

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

## <kbd>class</kbd> `DriverLog`
The driver instrumentation's recent output (``Device.driver_log()``), one entry per line. 

### <kbd>method</kbd> `DriverLog.__init__`

```python
__init__(lines: 'list[str]')
```

---

#### <kbd>property</kbd> DriverLog.bytes

---

#### <kbd>property</kbd> DriverLog.text

The lines joined with ``\n``. 

---

### <kbd>method</kbd> `DriverLog.save`

```python
save(path: 'str | os.PathLike[str]') → pathlib.Path
```

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

## <kbd>class</kbd> `Recording`
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. 

### <kbd>method</kbd> `Recording.__init__`

```python
__init__(data: 'builtins.bytes', format: 'str')
```

---

#### <kbd>property</kbd> Recording.bytes

Encoded recording bytes. 

---

### <kbd>method</kbd> `Recording.save`

```python
save(path: 'str | os.PathLike[str]') → pathlib.Path
```

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

## <kbd>class</kbd> `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. 

### <kbd>method</kbd> `Capture.__init__`

```python
__init__(
    serial: 'str',
    screenshot: 'Screenshot | None',
    hierarchy: 'Hierarchy | None',
    info: 'DeviceInfo | None',
    driver_log: 'DriverLog | None',
    failures: 'dict[str, BaseException]'
)
```

---

#### <kbd>property</kbd> Capture.artifacts

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

---

### <kbd>method</kbd> `Capture.save_to`

```python
save_to(
    directory: 'str | os.PathLike[str]',
    prefix: 'str | None' = None
) → list[pathlib.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. 

