Custom Search

Wednesday, October 5, 2011

Python Selenium WebDriver GUI Tests using PyVirtualDisplay Xvfb and without X-server

Python Selenium WebDriver GUI Tests using PyVirtualDisplay, Xvfb and
without X-server

I need to integrate my functional UI tests (Selenium/WebDriver) with
my Jenkins CI system. The problem is that my Jenkins CI server has no
display, so I must run my GUI tests in a headless X-server.

A colleague pointed me to PyVirtualDisplay, a Python wrapper for Xvfb
and Xephyr.

This makes running headless Python Selenium/WebDriver tests very easy.

Here is some Python code showing WebDriver with a virtual display
provided by Xvfb:


#!/usr/bin/env python

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))
display.start()

# now Firefox will run in a virtual display.
# you will not see the browser.
browser = webdriver.Firefox()
browser.get('http://www.google.com')
print browser.title
browser.quit()
display.stop()


install PyVirtualDisplay on Ubuntu/Debian:
==================================
$ sudo apt-get install xvfb xserver-xephyr python-pip
$ sudo pip install pyvirtualdisplay

1 comment:

  1. Get sweet, beautiful, heartfelt wedding anniversary wishes for wife, and make her moments so spectacular by expressing your love, care. 10 Year Anniversary Quotes To Wife

    ReplyDelete