Skip to content

Commit 5ab75a3

Browse files
committed
Make --headless mode the default setting on Linux
1 parent 1d1345e commit 5ab75a3

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

seleniumbase/plugins/pytest_plugin.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import optparse
55
import pytest
6+
import sys
67
from seleniumbase import config as sb_config
78
from seleniumbase.core import log_helper
89
from seleniumbase.core import proxy_helper
@@ -296,7 +297,16 @@ def pytest_configure(config):
296297
sb_config.save_screenshot = config.getoption('save_screenshot')
297298
sb_config.visual_baseline = config.getoption('visual_baseline')
298299
sb_config.timeout_multiplier = config.getoption('timeout_multiplier')
299-
sb_config.pytest_html_report = config.getoption("htmlpath") # --html=FILE
300+
sb_config.pytest_html_report = config.getoption('htmlpath') # --html=FILE
301+
302+
if "linux" in sys.platform and (
303+
not sb_config.headed and not sb_config.headless):
304+
print(
305+
"(Running with --headless on Linux. "
306+
"Use --headed or --gui to override.)")
307+
sb_config.headless = True
308+
if not sb_config.headless:
309+
sb_config.headed = True
300310

301311
if sb_config.with_testing_base:
302312
log_helper.log_folder_setup(sb_config.log_path, sb_config.archive_logs)

seleniumbase/plugins/selenium_plugin.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
by providing a WebDriver object for the tests to use.
44
"""
55

6+
import sys
67
from nose.plugins import Plugin
7-
from pyvirtualdisplay import Display
88
from seleniumbase.core import proxy_helper
99
from seleniumbase.fixtures import constants
1010

@@ -268,10 +268,26 @@ def beforeTest(self, test):
268268
if test.test.servername != "localhost":
269269
# Use Selenium Grid (Use --server=127.0.0.1 for localhost Grid)
270270
test.test.use_grid = True
271+
if "linux" in sys.platform and (
272+
not self.options.headed and not self.options.headless):
273+
print(
274+
"(Running with --headless on Linux. "
275+
"Use --headed or --gui to override.)")
276+
self.options.headless = True
277+
test.test.headless = True
278+
if not self.options.headless:
279+
self.options.headed = True
280+
test.test.headed = True
271281
if self.options.headless:
272-
self.display = Display(visible=0, size=(1920, 1200))
273-
self.display.start()
274-
self.headless_active = True
282+
try:
283+
from pyvirtualdisplay import Display
284+
self.display = Display(visible=0, size=(1440, 1080))
285+
self.display.start()
286+
self.headless_active = True
287+
except Exception:
288+
# pyvirtualdisplay might not be necessary anymore because
289+
# Chrome and Firefox now have built-in headless displays
290+
pass
275291
# The driver will be received later
276292
self.driver = None
277293
test.test.driver = self.driver

0 commit comments

Comments
 (0)