Skip to content

Commit 4551dad

Browse files
authored
Merge pull request #621 from seleniumbase/swiftshader-command-line-option
Add the "--swiftshader" command-line option
2 parents acd9be3 + 3036350 commit 4551dad

File tree

8 files changed

+43
-15
lines changed

8 files changed

+43
-15
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ SeleniumBase provides additional Pytest command-line options for tests:
326326
--disable-csp # (This disables the Content Security Policy of websites.)
327327
--enable-sync # (The option to enable "Chrome Sync".)
328328
--use-auto-ext # (The option to use Chrome's automation extension.)
329+
--swiftshader # (The option to use Chrome's "--use-gl=swiftshader" feature.)
329330
--incognito # (The option to enable Chrome's Incognito mode.)
330331
--guest # (The option to enable Chrome's Guest mode.)
331332
--devtools # (The option to open Chrome's DevTools when the browser opens.)

examples/raw_parameter_script.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
sb.settings_file = None
7272
sb.user_data_dir = None
7373
sb.proxy_string = None
74+
sb.swiftshader = False
7475
sb.ad_block_on = False
7576
sb.highlights = None
7677
sb.check_js = False

help_docs/customizing_test_runs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ SeleniumBase provides additional Pytest command-line options for tests:
123123
--disable-csp # (This disables the Content Security Policy of websites.)
124124
--enable-sync # (The option to enable "Chrome Sync".)
125125
--use-auto-ext # (The option to use Chrome's automation extension.)
126+
--swiftshader # (The option to use Chrome's "--use-gl=swiftshader" feature.)
126127
--incognito # (The option to enable Chrome's Incognito mode.)
127128
--guest # (The option to enable Chrome's Guest mode.)
128129
--devtools # (The option to open Chrome's DevTools when the browser opens.)

seleniumbase/core/browser_launcher.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ def _set_chrome_options(
132132
downloads_path, headless,
133133
proxy_string, proxy_auth, proxy_user, proxy_pass,
134134
user_agent, disable_csp, enable_sync, use_auto_ext,
135-
no_sandbox, disable_gpu, incognito, guest_mode, devtools, block_images,
136-
user_data_dir, extension_zip, extension_dir, servername,
135+
no_sandbox, disable_gpu, incognito, guest_mode, devtools, swiftshader,
136+
block_images, user_data_dir, extension_zip, extension_dir, servername,
137137
mobile_emulator, device_width, device_height, device_pixel_ratio):
138138
chrome_options = webdriver.ChromeOptions()
139139
prefs = {
@@ -236,9 +236,10 @@ def _set_chrome_options(
236236
chrome_options.add_argument("--headless")
237237
# if headless or disable_gpu:
238238
chrome_options.add_argument("--disable-gpu") # (Now always on)
239-
chrome_options.add_argument("--use-gl=swiftshader")
240239
# if (headless and "linux" in PLATFORM) or no_sandbox:
241240
chrome_options.add_argument("--no-sandbox") # (Now always on)
241+
if swiftshader:
242+
chrome_options.add_argument("--use-gl=swiftshader")
242243
if "linux" in PLATFORM:
243244
chrome_options.add_argument("--disable-dev-shm-usage")
244245
return chrome_options
@@ -361,7 +362,7 @@ def get_driver(browser_name, headless=False, use_grid=False,
361362
disable_csp=None, enable_sync=None, use_auto_ext=None,
362363
no_sandbox=None, disable_gpu=None,
363364
incognito=None, guest_mode=None, devtools=None,
364-
block_images=None, user_data_dir=None,
365+
swiftshader=None, block_images=None, user_data_dir=None,
365366
extension_zip=None, extension_dir=None,
366367
test_id=None, mobile_emulator=False, device_width=None,
367368
device_height=None, device_pixel_ratio=None):
@@ -400,14 +401,15 @@ def get_driver(browser_name, headless=False, use_grid=False,
400401
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
401402
cap_file, cap_string, disable_csp, enable_sync, use_auto_ext,
402403
no_sandbox, disable_gpu, incognito, guest_mode, devtools,
403-
block_images, user_data_dir, extension_zip, extension_dir, test_id,
404+
swiftshader, block_images, user_data_dir,
405+
extension_zip, extension_dir, test_id,
404406
mobile_emulator, device_width, device_height, device_pixel_ratio)
405407
else:
406408
return get_local_driver(
407409
browser_name, headless, servername,
408410
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
409411
disable_csp, enable_sync, use_auto_ext, no_sandbox, disable_gpu,
410-
incognito, guest_mode, devtools, block_images,
412+
incognito, guest_mode, devtools, swiftshader, block_images,
411413
user_data_dir, extension_zip, extension_dir,
412414
mobile_emulator, device_width, device_height, device_pixel_ratio)
413415

@@ -416,7 +418,7 @@ def get_remote_driver(
416418
browser_name, headless, servername, port, proxy_string, proxy_auth,
417419
proxy_user, proxy_pass, user_agent, cap_file, cap_string,
418420
disable_csp, enable_sync, use_auto_ext, no_sandbox, disable_gpu,
419-
incognito, guest_mode, devtools, block_images,
421+
incognito, guest_mode, devtools, swiftshader, block_images,
420422
user_data_dir, extension_zip, extension_dir, test_id,
421423
mobile_emulator, device_width, device_height, device_pixel_ratio):
422424
downloads_path = download_helper.get_downloads_folder()
@@ -448,7 +450,7 @@ def get_remote_driver(
448450
downloads_path, headless,
449451
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
450452
disable_csp, enable_sync, use_auto_ext, no_sandbox, disable_gpu,
451-
incognito, guest_mode, devtools, block_images,
453+
incognito, guest_mode, devtools, swiftshader, block_images,
452454
user_data_dir, extension_zip, extension_dir, servername,
453455
mobile_emulator, device_width, device_height, device_pixel_ratio)
454456
capabilities = chrome_options.to_capabilities()
@@ -572,7 +574,7 @@ def get_local_driver(
572574
browser_name, headless, servername,
573575
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
574576
disable_csp, enable_sync, use_auto_ext, no_sandbox, disable_gpu,
575-
incognito, guest_mode, devtools, block_images,
577+
incognito, guest_mode, devtools, swiftshader, block_images,
576578
user_data_dir, extension_zip, extension_dir,
577579
mobile_emulator, device_width, device_height, device_pixel_ratio):
578580
'''
@@ -663,7 +665,7 @@ def get_local_driver(
663665
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
664666
disable_csp, enable_sync, use_auto_ext,
665667
no_sandbox, disable_gpu, incognito, guest_mode, devtools,
666-
block_images, user_data_dir,
668+
swiftshader, block_images, user_data_dir,
667669
extension_zip, extension_dir, servername,
668670
mobile_emulator, device_width, device_height,
669671
device_pixel_ratio)
@@ -721,9 +723,9 @@ def get_local_driver(
721723
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
722724
disable_csp, enable_sync, use_auto_ext,
723725
no_sandbox, disable_gpu, incognito, guest_mode, devtools,
724-
block_images, user_data_dir, extension_zip, extension_dir,
725-
servername, mobile_emulator, device_width, device_height,
726-
device_pixel_ratio)
726+
swiftshader, block_images, user_data_dir, extension_zip,
727+
extension_dir, servername, mobile_emulator,
728+
device_width, device_height, device_pixel_ratio)
727729
if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
728730
try:
729731
make_driver_executable_if_not(LOCAL_CHROMEDRIVER)

seleniumbase/fixtures/base_case.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ def get_new_driver(self, browser=None, headless=None,
15921592
disable_csp=None, enable_sync=None, use_auto_ext=None,
15931593
no_sandbox=None, disable_gpu=None,
15941594
incognito=None, guest_mode=None, devtools=None,
1595-
block_images=None, user_data_dir=None,
1595+
swiftshader=None, block_images=None, user_data_dir=None,
15961596
extension_zip=None, extension_dir=None, is_mobile=False,
15971597
d_width=None, d_height=None, d_p_r=None):
15981598
""" This method spins up an extra browser for tests that require
@@ -1616,6 +1616,7 @@ def get_new_driver(self, browser=None, headless=None,
16161616
incognito - the option to enable Chrome's Incognito mode (Chrome)
16171617
guest - the option to enable Chrome's Guest mode (Chrome)
16181618
devtools - the option to open Chrome's DevTools on start (Chrome)
1619+
swiftshader the option to use "--use-gl=swiftshader" (Chrome-only)
16191620
block_images - the option to block images from loading (Chrome)
16201621
user_data_dir - Chrome's User Data Directory to use (Chrome-only)
16211622
extension_zip - A Chrome Extension ZIP file to use (Chrome-only)
@@ -1681,6 +1682,8 @@ def get_new_driver(self, browser=None, headless=None,
16811682
guest_mode = self.guest_mode
16821683
if devtools is None:
16831684
devtools = self.devtools
1685+
if swiftshader is None:
1686+
swiftshader = self.swiftshader
16841687
if block_images is None:
16851688
block_images = self.block_images
16861689
if user_data_dir is None:
@@ -1728,6 +1731,7 @@ def get_new_driver(self, browser=None, headless=None,
17281731
incognito=incognito,
17291732
guest_mode=guest_mode,
17301733
devtools=devtools,
1734+
swiftshader=swiftshader,
17311735
block_images=block_images,
17321736
user_data_dir=user_data_dir,
17331737
extension_zip=extension_zip,
@@ -5283,6 +5287,7 @@ def setUp(self, masterqa_mode=False):
52835287
self.incognito = sb_config.incognito
52845288
self.guest_mode = sb_config.guest_mode
52855289
self.devtools = sb_config.devtools
5290+
self.swiftshader = sb_config.swiftshader
52865291
self.user_data_dir = sb_config.user_data_dir
52875292
self.extension_zip = sb_config.extension_zip
52885293
self.extension_dir = sb_config.extension_dir
@@ -5445,6 +5450,7 @@ def setUp(self, masterqa_mode=False):
54455450
incognito=self.incognito,
54465451
guest_mode=self.guest_mode,
54475452
devtools=self.devtools,
5453+
swiftshader=self.swiftshader,
54485454
block_images=self.block_images,
54495455
user_data_dir=self.user_data_dir,
54505456
extension_zip=self.extension_zip,

seleniumbase/plugins/pytest_plugin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def pytest_addoption(parser):
4747
--disable-csp (This disables the Content Security Policy of websites.)
4848
--enable-sync (The option to enable "Chrome Sync".)
4949
--use-auto-ext (The option to use Chrome's automation extension.)
50+
--swiftshader (The option to use Chrome's "--use-gl=swiftshader" feature.)
5051
--incognito (The option to enable Chrome's Incognito mode.)
5152
--guest (The option to enable Chrome's Guest mode.)
5253
--devtools (The option to open Chrome's DevTools when the browser opens.)
@@ -377,6 +378,12 @@ def pytest_addoption(parser):
377378
default=False,
378379
help="""Using this enables the "Disable GPU" feature.
379380
(This setting is now always enabled by default.)""")
381+
parser.addoption('--swiftshader',
382+
action="store_true",
383+
dest='swiftshader',
384+
default=False,
385+
help="""Using this enables the "--use-gl=swiftshader"
386+
feature when running tests on Chrome.""")
380387
parser.addoption('--incognito', '--incognito_mode', '--incognito-mode',
381388
action="store_true",
382389
dest='incognito',
@@ -491,6 +498,7 @@ def pytest_configure(config):
491498
sb_config.use_auto_ext = config.getoption('use_auto_ext')
492499
sb_config.no_sandbox = config.getoption('no_sandbox')
493500
sb_config.disable_gpu = config.getoption('disable_gpu')
501+
sb_config.swiftshader = config.getoption('swiftshader')
494502
sb_config.incognito = config.getoption('incognito')
495503
sb_config.guest_mode = config.getoption('guest_mode')
496504
sb_config.devtools = config.getoption('devtools')

seleniumbase/plugins/selenium_plugin.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SeleniumBrowser(Plugin):
3838
--disable-csp (This disables the Content Security Policy of websites.)
3939
--enable-sync (The option to enable "Chrome Sync".)
4040
--use-auto-ext (The option to use Chrome's automation extension.)
41+
--swiftshader (The option to use Chrome's "--use-gl=swiftshader" feature.)
4142
--incognito (The option to enable Chrome's Incognito mode.)
4243
--guest (The option to enable Chrome's Guest mode.)
4344
--devtools (The option to open Chrome's DevTools when the browser opens.)
@@ -294,6 +295,13 @@ def options(self, parser, env):
294295
default=False,
295296
help="""Using this enables the "Disable GPU" feature.
296297
(This setting is now always enabled by default.)""")
298+
parser.add_option(
299+
'--swiftshader',
300+
action="store_true",
301+
dest='swiftshader',
302+
default=False,
303+
help="""Using this enables the "--use-gl=swiftshader"
304+
feature when running tests on Chrome.""")
297305
parser.add_option(
298306
'--incognito', '--incognito_mode', '--incognito-mode',
299307
action="store_true",
@@ -382,6 +390,7 @@ def beforeTest(self, test):
382390
test.test.use_auto_ext = self.options.use_auto_ext
383391
test.test.no_sandbox = self.options.no_sandbox
384392
test.test.disable_gpu = self.options.disable_gpu
393+
test.test.swiftshader = self.options.swiftshader
385394
test.test.incognito = self.options.incognito
386395
test.test.guest_mode = self.options.guest_mode
387396
test.test.devtools = self.options.devtools

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
setup(
5656
name='seleniumbase',
57-
version='1.42.9',
57+
version='1.42.10',
5858
description='Fast, Easy, and Reliable Browser Automation & Testing.',
5959
long_description=long_description,
6060
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)