Quick Start¶
Installation¶
pip install -e .
xdrive requires an X11 environment (real or virtual). For headless CI, see the Headless Display Setup guide.
Your First Test¶
from xdrive import XDrive, VirtualDisplay, expect
# Start a virtual X display and connect
with VirtualDisplay(width=1280, height=720) as vd:
with XDrive(display=vd, wm="./my_wm") as xd:
# Create a test window
win = xd.new_window(title="hello", size=(400, 300))
# Assert the window is mapped and has the right title
expect(win).to_be_mapped()
expect(win).to_have_title("hello")
# Interact with mouse and keyboard
xd.mouse.click(win)
xd.keyboard.type("Hello, world!")
# Take a screenshot
xd.screenshot("output/screenshot.png")
Using the Pytest Fixtures¶
xdrive ships as a pytest plugin. The built-in fixtures handle display and connection lifecycle for you:
def test_window_title(xd):
"""``xd`` is a per-test XDrive instance on a session-scoped Xvfb."""
win = xd.new_window(title="my window")
expect(win).to_have_title("my window")
Override the virtual_display or xd fixtures in your own conftest.py
to customise resolution, colour depth, or window manager command.
Key Concepts¶
Object |
Purpose |
|---|---|
|
Manage an Xvfb instance |
|
Main controller — windows, input, screenshots |
|
Query and manipulate a single X11 window |
|
Query display-wide state (window list, focus) |
|
Synthesise key events via XTest |
|
Synthesise pointer events via XTest |
|
Playwright-style fluent assertions |