# Screenshot testing \(\#45259\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/8c0b088366545e5050711066a4be666266f28110)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 8c0b088366545e5050711066a4be666266f28110

Requested commit: 8c0b088366545e5050711066a4be666266f28110

Commit: 8c0b088366545e5050711066a4be666266f28110

Tree: a3fd865d0ddaf9f2aa21e938b3f1004bb70b7ed4

Author: Richard Feldman

Committer: GitHub

## Message

````
Screenshot testing (#45259)

## Screenshot testing

Adds visual testing infrastructure for GPUI that captures screenshots by
rendering directly to Metal textures. The

The screenshots end up in `target/visual_tests/` and look like this:

<img width="2560" height="1600" alt="workspace_with_editor2"
src="https://github.com/user-attachments/assets/54112343-4af1-4347-9bab-f099de97dd29"
/>
<img width="2560" height="1600" alt="project_panel2"
src="https://github.com/user-attachments/assets/0cd54b61-dace-4398-a28e-0b4d7c2968f6"
/>


### Key Features

- **Direct texture capture**: Screenshots are captured by rendering the
scene to a Metal texture and reading pixels directly from GPU memory,
rather than using ScreenCaptureKit
- **No visibility requirements**: Windows don't need to be visible on
screen since we read directly from the render pipeline
- **Deterministic output**: Captures exactly what GPUI renders, not what
the OS compositor displays
- **No permissions needed**: Doesn't require Screen Recording permission
like ScreenCaptureKit would

### Running the Visual Tests

```bash
# Run visual tests (compares against baselines)
cargo run -p zed --bin visual_test_runner --features visual-tests

# Update baseline images (when UI intentionally changes)
UPDATE_BASELINE=1 cargo run -p zed --bin visual_test_runner --features visual-tests

# View the captured screenshots
open target/visual_tests/
```

### Implementation

- `Window::render_to_image()` - Renders the current scene to a texture
and returns an `RgbaImage`
- `MetalRenderer::render_to_image()` - Core implementation that renders
to a non-framebuffer-only texture
- `VisualTestAppContext` - Test context that uses real macOS platform
rendering
- `VisualTestAppContext::capture_screenshot()` - Synchronous screenshot
capture using direct texture rendering

### Usage

```rust
let mut cx = VisualTestAppContext::new();
let window = cx.open_window(...)?;
let screenshot: RgbaImage = cx.capture_screenshot(window.into())?;
```

Release Notes:

- N/A

---------

Co-authored-by: Amp <amp@ampcode.com>
````

## Parents

- [8ba030ab1e3ac7aed03e22f85e82842bb712e056](https://git.cafe/gitcafe/zed/commit/8ba030ab1e3ac7aed03e22f85e82842bb712e056?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/8c0b088366545e5050711066a4be666266f28110?format=markdown)
