Skip to content

Commit 7638877

Browse files
committed
The Selenium plugin will handle virtual display
1 parent ede0f02 commit 7638877

File tree

4 files changed

+23
-99
lines changed

4 files changed

+23
-99
lines changed

docker/docker_config.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[nosetests]
2-
with-selenium_docker=1
2+
with-selenium=1
33
with-testing_base=1
44
with-basic_test_info=1
55
nocapture=1

docker/docker_setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
entry_points={
2525
'nose.plugins': [
2626
'base_plugin = seleniumbase.plugins.base_plugin:Base',
27-
'selenium_docker = '
28-
'seleniumbase.plugins.docker_selenium_plugin:SeleniumBrowser',
27+
'selenium = seleniumbase.plugins.selenium_plugin:SeleniumBrowser',
2928
'page_source = seleniumbase.plugins.page_source:PageSource',
3029
'screen_shots = seleniumbase.plugins.screen_shots:ScreenShots',
3130
'test_info = seleniumbase.plugins.basic_test_info:BasicTestInfo',

seleniumbase/plugins/docker_selenium_plugin.py

Lines changed: 0 additions & 92 deletions
This file was deleted.

seleniumbase/plugins/selenium_plugin.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
from nose.plugins import Plugin
99
from selenium import webdriver
10+
from pyvirtualdisplay import Display
1011
from seleniumbase.core import selenium_launcher
1112
from seleniumbase.core import browser_launcher
1213
from seleniumbase.fixtures import constants
@@ -20,7 +21,10 @@ class SeleniumBrowser(Plugin):
2021
The following variables are made to the tests:
2122
self.options.browser -- the browser to use (--browser)
2223
self.options.server -- the server used by the test (--server)
23-
self.options.port -- the port used by thest (--port)
24+
self.options.port -- the port used by the test (--port)
25+
self.options.headless -- the option to run headlessly (--headless)
26+
self.options.demo_mode -- the option to slow down Selenium (--demo_mode)
27+
self.options.demo_sleep -- Selenium action delay in DemoMode (--demo_sleep)
2428
"""
2529
name = 'selenium' # Usage: --with-selenium
2630

@@ -46,6 +50,11 @@ def options(self, parser, env):
4650
default='4444',
4751
help="""Designates the port used by the test.
4852
Default: 4444.""")
53+
parser.add_option('--headless', action="store_true",
54+
dest='headless',
55+
default=False,
56+
help="""Using this makes Webdriver run headlessly,
57+
which is useful inside a Linux Docker.""")
4958
parser.add_option('--demo_mode', action="store_true",
5059
dest='demo_mode',
5160
default=False,
@@ -84,6 +93,7 @@ def configure(self, options, conf):
8493
self.browser_settings["version"] = options.browser_version
8594

8695
self.options = options
96+
self.headless_active = False
8797

8898
if (self.options.servername == "localhost" and
8999
self.options.browser == constants.Browser.HTML_UNIT):
@@ -95,6 +105,10 @@ def beforeTest(self, test):
95105
""" Running Selenium locally will be handled differently
96106
from how Selenium is run remotely, such as from Jenkins. """
97107

108+
if self.options.headless:
109+
self.display = Display(visible=0, size=(1200, 800))
110+
self.display.start()
111+
self.headless_active = True
98112
if self.options.servername == "localhost":
99113
try:
100114
self.driver = self.__select_browser(self.options.browser)
@@ -127,19 +141,22 @@ def beforeTest(self, test):
127141
except Exception as err:
128142
print "Attempt #%s to connect to Selenium failed" % i
129143
if i < 3:
130-
print "Retrying in 15 seconds..."
131-
time.sleep(15)
144+
print "Retrying in 3 seconds..."
145+
time.sleep(3)
132146
if not connected:
133147
print "Error starting/connecting to Selenium:"
134148
print err
135-
print "\n\n\n"
149+
print "\n\n"
136150
os.kill(os.getpid(), 9)
137151

138152
def afterTest(self, test):
139153
try:
140154
self.driver.quit()
141155
except:
142156
print "No driver to quit."
157+
if self.options.headless:
158+
if self.headless_active:
159+
self.display.stop()
143160

144161
def __select_browser(self, browser_name):
145162
if (self.options.servername != "localhost" or

0 commit comments

Comments
 (0)