### Install xvfbwrapper Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Install the library using pip. Ensure Python 3.10+ and Xvfb are installed on your system. ```bash pip install xvfbwrapper ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Sets up a virtual environment and installs the necessary packages for development and testing of xvfbwrapper. Includes editable installation. ```bash python -m venv venv source ./venv/bin/activate pip install --editable --group dev --group test . ``` -------------------------------- ### Basic Xvfb Usage Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Start and stop Xvfb manually. Always use a try/finally block to ensure the display is stopped, preventing leftover files in /tmp. ```python from xvfbwrapper import Xvfb xvfb = Xvfb() xvfb.start() try: # launch stuff inside virtual display here finally: xvfb.stop() ``` -------------------------------- ### Specify Xvfb Display Geometry Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Start Xvfb with a specific screen resolution. The display will be stopped automatically if used as a context manager. ```python from xvfbwrapper import Xvfb xvfb = Xvfb(width=1280, height=720) xvfb.start() ``` -------------------------------- ### Xvfb Usage as a Context Manager Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Use Xvfb as a context manager for automatic start and stop. The display stops when the block completes. ```python from xvfbwrapper import Xvfb with Xvfb(): # launch stuff inside virtual display here # (Xvfb will stop when this block completes) ``` -------------------------------- ### Specify Xvfb Options with Keyword Arguments Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Pass common Xvfb arguments with a '-' prefix as keyword arguments. For example, '-nolisten tcp' prevents Xvfb from listening on TCP connections. ```python from xvfbwrapper import Xvfb xvfb = Xvfb(nolisten="tcp") xvfb.start() # Xvfb will be called with the `-nolisten tcp` argument ``` -------------------------------- ### Specify Xvfb Display Number Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Start Xvfb on a specific display number. The display will be stopped automatically if used as a context manager. ```python from xvfbwrapper import Xvfb xvfb = Xvfb(display=23) xvfb.start() # Xvfb will start on display :23 ``` -------------------------------- ### Clone xvfbwrapper Repository Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Instructions for cloning the xvfbwrapper project from GitHub. This is the first step in contributing to the project. ```bash git clone https://github.com//xvfbwrapper.git cd xvfbwrapper ``` -------------------------------- ### Run xvfbwrapper Tests with Tox Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Runs all tests, linting, and type checking across multiple supported Python environments using tox. ```bash tox ``` -------------------------------- ### Multithreaded Xvfb Execution Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Demonstrates how to run multiple isolated Xvfb instances concurrently using separate environments. Ensure you use a copy of os.environ for isolation. ```python import os from xvfbwrapper import Xvfb isolated_environment1 = os.environ.copy() xvfb1 = Xvfb(environ=isolated_environment1) xvfb1.start() isolated_environment2 = os.environ.copy() xvfb2 = Xvfb(environ=isolated_environment2) xvfb2.start() try: # launch stuff inside virtual displays here finally: xvfb1.stop() xvfb2.stop() ``` -------------------------------- ### Run xvfbwrapper Tests with Pytest Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Executes all tests for xvfbwrapper using the pytest framework in the default Python environment. ```bash pytest ``` -------------------------------- ### Headless Selenium WebDriver Tests with Xvfb Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Shows how to integrate xvfbwrapper with Selenium for running headless Chrome tests. It ensures X11 is used and manages the lifecycle of the virtual display and browser. ```python import os import unittest from selenium import webdriver from xvfbwrapper import Xvfb # force X11 in case we are running on a Wayland system os.environ["XDG_SESSION_TYPE"] = "x11" class TestPage(unittest.TestCase): def setUp(self): xvfb = Xvfb() xvfb.start() self.driver = webdriver.Chrome() self.addCleanup(xvfb.stop) self.addCleanup(self.driver.quit) def test_selenium_homepage(self): self.driver.get("https://www.selenium.dev") self.assertIn("Selenium", self.driver.title) if __name__ == "__main__": unittest.main() ``` -------------------------------- ### Specify Xvfb Options with extra_args Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Pass various types of Xvfb arguments, including unary, prefixed unary, and arguments with parameters, using the 'extra_args' sequence. ```python from xvfbwrapper import Xvfb xvfb = Xvfb(extra_args=("ttyxx", "-nocursor", "+extension", "RANDR")) xvfb.start() # Xvfb will be called with the `ttyxx -nocursor +extension RANDR` arguments ``` -------------------------------- ### Set XDG_SESSION_TYPE for Wayland Compatibility Source: https://github.com/cgoldberg/xvfbwrapper/blob/master/README.md Ensure GUI applications use the X11 backend in Wayland sessions by setting XDG_SESSION_TYPE=x11. This is useful when running Xvfb in a Wayland environment. ```python from xvfbwrapper import Xvfb xvfb = Xvfb(set_xdg_session_type=True) xvfb.start() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.