I have about 20 selenium tests that I run frequently on a headless Ubuntu 14.04 VM. Below is an example:
import time
import random
import requests
from selenium import webdriver
import datetime
import MySQLdb as mdb
import sys
import socks
from pyvirtualdisplay import Display
if (sys.platform != "win32"):
print("Starting display.")
display = Display(visible=0, size=(800, 600))
display.start()
ChromeOptions = webdriver.ChromeOptions()
ChromeOptions.add_argument('window-size=1200x600')
Prefs = {"profile.managed_default_content_settings.images": 2}
ChromeOptions.add_experimental_option("prefs", Prefs)
if (sys.platform != "win32"):
print("Unix System being used, proceeding accordingly.")
ChromeOptions.binary_location = '/usr/bin/google-chrome-unstable'
ChromeOptions.add_argument("--disable-extensions")
global driver
driver = webdriver.Chrome(chrome_options=ChromeOptions)
driver.set_page_load_timeout(45)
driver.get("https://google.com")
print(driver.title)
As you can see, if the platform is not win32, it will create a display and start it:
if (sys.platform != "win32"):
print("Starting display.")
display = Display(visible=0, size=(800, 600))
display.start()
Every single one of the 20 test suites creates a display, and starts it. Is there a way to make it so ALL of them connect to the same display? Thus, eliminating a ton if CPU/RAM usage as I won't have 20 instances of XVFB running? If so, can you provide a working example in python and any necessary unix commands needed to run it?