Making all tests use the same XVFB display

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Making all tests use the same XVFB display

Jorge Delgado

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?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/5484d377-f97f-4e25-a9c8-9d31a16bd1db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Making all tests use the same XVFB display

thivyae
Hi,why are you setting XVFB inside your selenium script?
Instead,I suggest you to have it as a shell command or any gradle or maven task to be executed before you run your tests.

On Sunday, June 4, 2017 at 9:56:09 AM UTC+5:30, Jorge Delgado wrote:

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("<a href="https://google.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://google.com&#39;;return true;" onclick="this.href=&#39;https://google.com&#39;;return true;">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?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/3da39e5c-1dbc-45f0-8960-781491c62d06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.