Skip to content

Commit 815dad7

Browse files
authored
Merge pull request #541 from seleniumbase/guest-mode-and-devtools
Add Guest Mode and DevTools options for Chromium
2 parents 9dc1a87 + 211a0aa commit 815dad7

File tree

10 files changed

+100
-30
lines changed

10 files changed

+100
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ latest_logs
7171
log_archives
7272
archived_logs
7373
geckodriver.log
74+
pytestdebug.log
7475

7576
# Reports
7677
latest_report

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ If multiple versions of Python are installed, be specific (E.g. use ``python3``
4646
pip install seleniumbase
4747
```
4848
* Add ``--upgrade`` OR ``-U`` to upgrade an installation.
49-
* Add ``--force-reinstall`` for a clean install.
49+
* Add ``--force-reinstall`` to also upgrade dependencies.
5050

5151
### <img src="https://cdn2.hubspot.net/hubfs/100006/images/super_square_logo_3a.png" title="SeleniumBase" height="32"> Download a webdriver:
5252

examples/raw_parameter_script.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
sb.environment = "test"
3737
sb.user_agent = None
3838
sb.incognito = False
39+
sb.guest_mode = False
40+
sb.devtools = False
3941
sb.mobile_emulator = False
4042
sb.device_metrics = None
4143
sb.extension_zip = None

pytest.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
addopts = --capture=no --ignore conftest.py -p no:cacheprovider
55

66
# Ignore warnings such as DeprecationWarning and pytest.PytestUnknownMarkWarning
7-
filterwarnings = ignore::pytest.PytestWarning
7+
filterwarnings =
8+
ignore::pytest.PytestWarning
9+
ignore:.*U.*mode is deprecated:DeprecationWarning
810

911
# Configure the junit_family option explicitly:
1012
junit_family = legacy

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ nose==1.3.7
88
ipdb==0.13.2
99
idna==2.9
1010
chardet==3.0.4
11-
urllib3==1.25.8
11+
urllib3==1.25.9
1212
requests==2.23.0
1313
selenium==3.141.0
1414
pluggy==0.13.1

seleniumbase/core/browser_launcher.py

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +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, no_sandbox, disable_gpu,
135-
incognito, user_data_dir, extension_zip, extension_dir, servername,
135+
incognito, guest_mode, devtools,
136+
user_data_dir, extension_zip, extension_dir, servername,
136137
mobile_emulator, device_width, device_height, device_pixel_ratio):
137138
chrome_options = webdriver.ChromeOptions()
138139
prefs = {
@@ -145,10 +146,15 @@ def _set_chrome_options(
145146
}
146147
chrome_options.add_experimental_option("prefs", prefs)
147148
chrome_options.add_experimental_option("w3c", True)
148-
chrome_options.add_experimental_option(
149-
"excludeSwitches", ["enable-automation", "enable-logging"])
150-
if servername == "localhost" or servername == "127.0.0.1":
151-
chrome_options.add_experimental_option("useAutomationExtension", False)
149+
if enable_sync:
150+
chrome_options.add_experimental_option(
151+
"excludeSwitches",
152+
["enable-automation", "enable-logging", "disable-sync"])
153+
chrome_options.add_argument("--enable-sync")
154+
else:
155+
chrome_options.add_experimental_option(
156+
"excludeSwitches",
157+
["enable-automation", "enable-logging"])
152158
if mobile_emulator:
153159
emulator_settings = {}
154160
device_metrics = {}
@@ -166,12 +172,13 @@ def _set_chrome_options(
166172
emulator_settings["userAgent"] = user_agent
167173
chrome_options.add_experimental_option(
168174
"mobileEmulation", emulator_settings)
169-
if enable_sync:
170-
chrome_options.add_experimental_option(
171-
"excludeSwitches", ["disable-sync"])
172175
chrome_options.add_argument("--enable-sync")
173176
if incognito:
174177
chrome_options.add_argument("--incognito")
178+
elif guest_mode:
179+
chrome_options.add_argument("--guest")
180+
else:
181+
pass
175182
if user_data_dir:
176183
abs_path = os.path.abspath(user_data_dir)
177184
chrome_options.add_argument("user-data-dir=%s" % abs_path)
@@ -189,6 +196,8 @@ def _set_chrome_options(
189196
chrome_options.add_argument("--log-level=3")
190197
chrome_options.add_argument("--no-first-run")
191198
chrome_options.add_argument("--ignore-certificate-errors")
199+
if devtools and not headless:
200+
chrome_options.add_argument("--auto-open-devtools-for-tabs")
192201
chrome_options.add_argument("--allow-file-access-from-files")
193202
chrome_options.add_argument("--allow-insecure-localhost")
194203
chrome_options.add_argument("--allow-running-insecure-content")
@@ -199,10 +208,15 @@ def _set_chrome_options(
199208
chrome_options.add_argument("--disable-single-click-autofill")
200209
chrome_options.add_argument("--disable-translate")
201210
chrome_options.add_argument("--disable-web-security")
211+
if servername == "localhost" or servername == "127.0.0.1":
212+
chrome_options.add_experimental_option("useAutomationExtension", False)
202213
if (settings.DISABLE_CSP_ON_CHROME or disable_csp) and not headless:
203214
# Headless Chrome doesn't support extensions, which are required
204215
# for disabling the Content Security Policy on Chrome
205216
chrome_options = _add_chrome_disable_csp_extension(chrome_options)
217+
elif not extension_zip and not extension_dir:
218+
if servername == "localhost" or servername == "127.0.0.1":
219+
chrome_options.add_argument("--disable-extensions")
206220
if proxy_string:
207221
if proxy_auth:
208222
chrome_options = _add_chrome_proxy_extension(
@@ -333,8 +347,9 @@ def get_driver(browser_name, headless=False, use_grid=False,
333347
servername='localhost', port=4444, proxy_string=None,
334348
user_agent=None, cap_file=None, disable_csp=None,
335349
enable_sync=None, no_sandbox=None, disable_gpu=None,
336-
incognito=None, user_data_dir=None, extension_zip=None,
337-
extension_dir=None, mobile_emulator=False, device_width=None,
350+
incognito=None, guest_mode=None, devtools=None,
351+
user_data_dir=None, extension_zip=None, extension_dir=None,
352+
mobile_emulator=False, device_width=None,
338353
device_height=None, device_pixel_ratio=None):
339354
proxy_auth = False
340355
proxy_user = None
@@ -370,22 +385,25 @@ def get_driver(browser_name, headless=False, use_grid=False,
370385
browser_name, headless, servername, port,
371386
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
372387
cap_file, disable_csp, enable_sync, no_sandbox, disable_gpu,
373-
incognito, user_data_dir, extension_zip, extension_dir,
388+
incognito, guest_mode, devtools,
389+
user_data_dir, extension_zip, extension_dir,
374390
mobile_emulator, device_width, device_height, device_pixel_ratio)
375391
else:
376392
return get_local_driver(
377393
browser_name, headless, servername,
378394
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
379-
disable_csp, enable_sync, no_sandbox, disable_gpu, incognito,
380-
user_data_dir, extension_zip, extension_dir, mobile_emulator,
381-
device_width, device_height, device_pixel_ratio)
395+
disable_csp, enable_sync, no_sandbox, disable_gpu,
396+
incognito, guest_mode, devtools,
397+
user_data_dir, extension_zip, extension_dir,
398+
mobile_emulator, device_width, device_height, device_pixel_ratio)
382399

383400

384401
def get_remote_driver(
385402
browser_name, headless, servername, port, proxy_string, proxy_auth,
386403
proxy_user, proxy_pass, user_agent, cap_file, disable_csp,
387-
enable_sync, no_sandbox, disable_gpu, incognito, user_data_dir,
388-
extension_zip, extension_dir,
404+
enable_sync, no_sandbox, disable_gpu,
405+
incognito, guest_mode, devtools,
406+
user_data_dir, extension_zip, extension_dir,
389407
mobile_emulator, device_width, device_height, device_pixel_ratio):
390408
downloads_path = download_helper.get_downloads_folder()
391409
download_helper.reset_downloads_folder()
@@ -397,7 +415,8 @@ def get_remote_driver(
397415
chrome_options = _set_chrome_options(
398416
downloads_path, headless,
399417
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
400-
disable_csp, enable_sync, no_sandbox, disable_gpu, incognito,
418+
disable_csp, enable_sync, no_sandbox, disable_gpu,
419+
incognito, guest_mode, devtools,
401420
user_data_dir, extension_zip, extension_dir, servername,
402421
mobile_emulator, device_width, device_height, device_pixel_ratio)
403422
capabilities = chrome_options.to_capabilities()
@@ -508,7 +527,8 @@ def get_remote_driver(
508527
def get_local_driver(
509528
browser_name, headless, servername,
510529
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
511-
disable_csp, enable_sync, no_sandbox, disable_gpu, incognito,
530+
disable_csp, enable_sync, no_sandbox, disable_gpu,
531+
incognito, guest_mode, devtools,
512532
user_data_dir, extension_zip, extension_dir,
513533
mobile_emulator, device_width, device_height, device_pixel_ratio):
514534
'''
@@ -597,7 +617,8 @@ def get_local_driver(
597617
chrome_options = _set_chrome_options(
598618
downloads_path, headless,
599619
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
600-
disable_csp, enable_sync, no_sandbox, disable_gpu, incognito,
620+
disable_csp, enable_sync, no_sandbox, disable_gpu,
621+
incognito, guest_mode, devtools,
601622
user_data_dir, extension_zip, extension_dir, servername,
602623
mobile_emulator, device_width, device_height,
603624
device_pixel_ratio)
@@ -652,7 +673,8 @@ def get_local_driver(
652673
chrome_options = _set_chrome_options(
653674
downloads_path, headless,
654675
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
655-
disable_csp, enable_sync, no_sandbox, disable_gpu, incognito,
676+
disable_csp, enable_sync, no_sandbox, disable_gpu,
677+
incognito, guest_mode, devtools,
656678
user_data_dir, extension_zip, extension_dir, servername,
657679
mobile_emulator, device_width, device_height,
658680
device_pixel_ratio)

seleniumbase/fixtures/base_case.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,8 @@ def get_new_driver(self, browser=None, headless=None,
15231523
servername=None, port=None, proxy=None, agent=None,
15241524
switch_to=True, cap_file=None, disable_csp=None,
15251525
enable_sync=None, no_sandbox=None, disable_gpu=None,
1526-
incognito=None, user_data_dir=None, extension_zip=None,
1526+
incognito=None, guest_mode=None, devtools=None,
1527+
user_data_dir=None, extension_zip=None,
15271528
extension_dir=None, is_mobile=False,
15281529
d_width=None, d_height=None, d_p_r=None):
15291530
""" This method spins up an extra browser for tests that require
@@ -1543,6 +1544,8 @@ def get_new_driver(self, browser=None, headless=None,
15431544
no_sandbox - the option to enable the "No-Sandbox" feature (Chrome)
15441545
disable_gpu - the option to enable Chrome's "Disable GPU" feature
15451546
incognito - the option to enable Chrome's Incognito mode (Chrome)
1547+
guest - the option to enable Chrome's Guest mode (Chrome)
1548+
devtools - the option to open Chrome's DevTools on start (Chrome)
15461549
user_data_dir - Chrome's User Data Directory to use (Chrome-only)
15471550
extension_zip - A Chrome Extension ZIP file to use (Chrome-only)
15481551
extension_dir - A Chrome Extension folder to use (Chrome-only)
@@ -1601,6 +1604,10 @@ def get_new_driver(self, browser=None, headless=None,
16011604
disable_gpu = self.disable_gpu
16021605
if incognito is None:
16031606
incognito = self.incognito
1607+
if guest_mode is None:
1608+
guest_mode = self.guest_mode
1609+
if devtools is None:
1610+
devtools = self.devtools
16041611
if user_data_dir is None:
16051612
user_data_dir = self.user_data_dir
16061613
if extension_zip is None:
@@ -1639,6 +1646,8 @@ def get_new_driver(self, browser=None, headless=None,
16391646
no_sandbox=no_sandbox,
16401647
disable_gpu=disable_gpu,
16411648
incognito=incognito,
1649+
guest_mode=guest_mode,
1650+
devtools=devtools,
16421651
user_data_dir=user_data_dir,
16431652
extension_zip=extension_zip,
16441653
extension_dir=extension_dir,
@@ -4532,6 +4541,8 @@ def setUp(self, masterqa_mode=False):
45324541
self.no_sandbox = sb_config.no_sandbox
45334542
self.disable_gpu = sb_config.disable_gpu
45344543
self.incognito = sb_config.incognito
4544+
self.guest_mode = sb_config.guest_mode
4545+
self.devtools = sb_config.devtools
45354546
self.user_data_dir = sb_config.user_data_dir
45364547
self.extension_zip = sb_config.extension_zip
45374548
self.extension_dir = sb_config.extension_dir
@@ -4687,6 +4698,8 @@ def setUp(self, masterqa_mode=False):
46874698
no_sandbox=self.no_sandbox,
46884699
disable_gpu=self.disable_gpu,
46894700
incognito=self.incognito,
4701+
guest_mode=self.guest_mode,
4702+
devtools=self.devtools,
46904703
user_data_dir=self.user_data_dir,
46914704
extension_zip=self.extension_zip,
46924705
extension_dir=self.extension_dir,

seleniumbase/plugins/pytest_plugin.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ def pytest_addoption(parser):
4242
--disable-csp (This disables the Content Security Policy of websites.)
4343
--enable-sync (The option to enable "Chrome Sync".)
4444
--no-sandbox (The option to enable Chrome's "No-Sandbox" feature.)
45-
--disable_gpu (The option to enable Chrome's "Disable GPU" feature.)
45+
--disable-gpu (The option to enable Chrome's "Disable GPU" feature.)
4646
--incognito (The option to enable Chrome's Incognito mode.)
47+
--guest (The option to enable Chrome's Guest mode.)
48+
--devtools (The option to open Chrome's DevTools when the browser opens.)
4749
--reuse-session (The option to reuse the browser session between tests.)
48-
--maximize-window (The option to start with the web browser maximized.)
50+
--maximize (The option to start with the web browser maximized.)
4951
--save-screenshot (The option to save a screenshot after each test.)
5052
--visual-baseline (Set the visual baseline for Visual/Layout tests.)
5153
--timeout-multiplier=MULTIPLIER (Multiplies the default timeout values.)
@@ -331,11 +333,21 @@ def pytest_addoption(parser):
331333
dest='disable_gpu',
332334
default=False,
333335
help="""Using this enables the "Disable GPU" feature.""")
334-
parser.addoption('--incognito',
336+
parser.addoption('--incognito', '--incognito_mode', '--incognito-mode',
335337
action="store_true",
336338
dest='incognito',
337339
default=False,
338340
help="""Using this enables Chrome's Incognito mode.""")
341+
parser.addoption('--guest', '--guest_mode', '--guest-mode',
342+
action="store_true",
343+
dest='guest_mode',
344+
default=False,
345+
help="""Using this enables Chrome's Guest mode.""")
346+
parser.addoption('--devtools', '--open_devtools', '--open-devtools',
347+
action="store_true",
348+
dest='devtools',
349+
default=False,
350+
help="""Using this opens Chrome's DevTools.""")
339351
parser.addoption('--reuse_session', '--reuse-session',
340352
action="store_true",
341353
dest='reuse_session',
@@ -422,6 +434,8 @@ def pytest_configure(config):
422434
sb_config.no_sandbox = config.getoption('no_sandbox')
423435
sb_config.disable_gpu = config.getoption('disable_gpu')
424436
sb_config.incognito = config.getoption('incognito')
437+
sb_config.guest_mode = config.getoption('guest_mode')
438+
sb_config.devtools = config.getoption('devtools')
425439
sb_config.reuse_session = config.getoption('reuse_session')
426440
sb_config.shared_driver = None # The default driver for session reuse
427441
sb_config.maximize_option = config.getoption('maximize_option')

seleniumbase/plugins/selenium_plugin.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class SeleniumBrowser(Plugin):
3838
--no-sandbox (The option to enable Chrome's "No-Sandbox" feature.)
3939
--disable_gpu (The option to enable Chrome's "Disable GPU" feature.)
4040
--incognito (The option to enable Chrome's Incognito mode.)
41+
--guest (The option to enable Chrome's Guest mode.)
42+
--devtools (The option to open Chrome's DevTools when the browser opens.)
4143
--maximize-window (The option to start with the web browser maximized.)
4244
--save-screenshot (The option to save a screenshot after each test.)
4345
--visual-baseline (Set the visual baseline for Visual/Layout tests.)
@@ -265,11 +267,23 @@ def options(self, parser, env):
265267
default=False,
266268
help="""Using this enables the "Disable GPU" feature.""")
267269
parser.add_option(
268-
'--incognito',
270+
'--incognito', '--incognito_mode', '--incognito-mode',
269271
action="store_true",
270272
dest='incognito',
271273
default=False,
272274
help="""Using this enables Chrome's Incognito mode.""")
275+
parser.add_option(
276+
'--guest', '--guest_mode', '--guest-mode',
277+
action="store_true",
278+
dest='guest_mode',
279+
default=False,
280+
help="""Using this enables Chrome's Guest mode.""")
281+
parser.add_option(
282+
'--devtools', '--open_devtools', '--open-devtools',
283+
action="store_true",
284+
dest='devtools',
285+
default=False,
286+
help="""Using this opens Chrome's DevTools.""")
273287
parser.add_option(
274288
'--maximize_window', '--maximize-window', '--maximize',
275289
'--fullscreen',
@@ -338,6 +352,8 @@ def beforeTest(self, test):
338352
test.test.no_sandbox = self.options.no_sandbox
339353
test.test.disable_gpu = self.options.disable_gpu
340354
test.test.incognito = self.options.incognito
355+
test.test.guest_mode = self.options.guest_mode
356+
test.test.devtools = self.options.devtools
341357
test.test.maximize_option = self.options.maximize_option
342358
test.test.save_screenshot_after_test = self.options.save_screenshot
343359
test.test.visual_baseline = self.options.visual_baseline

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
setup(
4747
name='seleniumbase',
48-
version='1.37.2',
48+
version='1.37.3',
4949
description='Fast, Easy, and Reliable Browser Automation & Testing.',
5050
long_description=long_description,
5151
long_description_content_type='text/markdown',
@@ -90,7 +90,7 @@
9090
'ipdb',
9191
'idna==2.9', # Must stay in sync with "requests"
9292
'chardet==3.0.4', # Must stay in sync with "requests"
93-
'urllib3==1.25.8', # Must stay in sync with "requests"
93+
'urllib3==1.25.9', # Must stay in sync with "requests"
9494
'requests==2.23.0',
9595
'selenium==3.141.0',
9696
'pluggy==0.13.1',

0 commit comments

Comments
 (0)