sbvirtualdisplay
sbvirtualdisplay (current version 1.4.0) is a Python library that provides a customized virtual display for headless browser automation, primarily designed for use with SeleniumBase. It functions as a wrapper around Xvfb, Xephyr, or Xvnc programs, enabling browser tests to run in environments without a physical display server, which is particularly useful for Linux backend servers. The library is actively maintained with a steady release cadence.
Warnings
- breaking Support for Python 3.7 was dropped in version 1.4.0. Projects requiring Python 3.7 or older must use an earlier version of sbvirtualdisplay.
- breaking Support for Python 2.7 and Python 3.6 was dropped in version 1.3.0. The minimum supported Python version became 3.7 (and later 3.8 in 1.4.0).
- gotcha This library is primarily designed for Linux environments due to its reliance on the X Window System (via Xvfb, Xephyr, or Xvnc). It is not intended for use on Windows or macOS.
- gotcha The underlying X server (e.g., Xvfb) must be installed on the system where sbvirtualdisplay runs. This library is a Python wrapper and does not install the X server itself.
Install
-
pip install sbvirtualdisplay
Imports
- Display
from sbvirtualdisplay import Display
Quickstart
from sbvirtualdisplay import Display
# Example usage with context manager (recommended)
with Display(visible=0, size=(1440, 1880)):
# Code to run browser tests in a headless environment
print("Virtual display is active, running tests...")
# Example: driver = webdriver.Chrome(options=options)
# driver.get("http://example.com")
# ...
print("Virtual display is stopped.")
# Alternative usage with explicit start/stop
display = Display(visible=0, size=(1440, 1880))
try:
display.start()
print("Virtual display started, running tests...")
# Example: driver = webdriver.Firefox(options=options)
# driver.get("http://example.com")
# ...
finally:
display.stop()
print("Virtual display stopped.")