sbvirtualdisplay

1.4.0 · active · verified Sun Apr 12

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

Install

Imports

Quickstart

Initialize a virtual display with specified visibility and resolution, then execute browser automation code within its context. The context manager ensures the display is properly started and stopped.

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.")

view raw JSON →