Skip to content

Commit 6f4059d

Browse files
committed
Add Dark Mode option
1 parent 5f64da2 commit 6f4059d

File tree

8 files changed

+68
-1
lines changed

8 files changed

+68
-1
lines changed

examples/raw_parameter_script.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
sb.user_agent = None
5353
sb.incognito = False
5454
sb.guest_mode = False
55+
sb.dark_mode = False
5556
sb.devtools = False
5657
sb.mobile_emulator = False
5758
sb.device_metrics = None

seleniumbase/behave/behave_sb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
-D swiftshader (Use Chrome's SwiftShader Graphics Library.)
8282
-D incognito (Enable Chrome's Incognito mode.)
8383
-D guest (Enable Chrome's Guest mode.)
84+
-D dark (Enable Chrome's Dark mode.)
8485
-D devtools (Open Chrome's DevTools when the browser opens.)
8586
-D rs | -D reuse-session (Reuse browser session for all tests.)
8687
-D rcs | -D reuse-class-session (Reuse session for tests in class/feature)
@@ -156,6 +157,7 @@ def get_configured_sb(context):
156157
sb.user_agent = None
157158
sb.incognito = False
158159
sb.guest_mode = False
160+
sb.dark_mode = False
159161
sb.devtools = False
160162
sb.mobile_emulator = False
161163
sb.device_metrics = None
@@ -417,6 +419,10 @@ def get_configured_sb(context):
417419
if low_key in ["guest", "guest-mode", "guest_mode"]:
418420
sb.guest_mode = True
419421
continue
422+
# Handle: -D dark / dark-mode / dark_mode
423+
if low_key in ["dark", "dark-mode", "dark_mode"]:
424+
sb.dark_mode = True
425+
continue
420426
# Handle: -D devtools / open-devtools / open_devtools
421427
if low_key in ["devtools", "open-devtools", "open_devtools"]:
422428
sb.devtools = True

seleniumbase/core/browser_launcher.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ def _set_chrome_options(
510510
headless2,
511511
incognito,
512512
guest_mode,
513+
dark_mode,
513514
devtools,
514515
remote_debug,
515516
enable_3d_apis,
@@ -662,6 +663,8 @@ def _set_chrome_options(
662663
chrome_options.add_argument("--guest")
663664
else:
664665
pass
666+
if dark_mode:
667+
chrome_options.add_argument("--enable-features=WebContentsForceDark")
665668
if user_data_dir and not is_using_uc(undetectable, browser_name):
666669
abs_path = os.path.abspath(user_data_dir)
667670
chrome_options.add_argument("--user-data-dir=%s" % abs_path)
@@ -1067,6 +1070,7 @@ def get_driver(
10671070
headless2=False,
10681071
incognito=False,
10691072
guest_mode=False,
1073+
dark_mode=False,
10701074
devtools=False,
10711075
remote_debug=False,
10721076
enable_3d_apis=False,
@@ -1273,6 +1277,7 @@ def get_driver(
12731277
headless2,
12741278
incognito,
12751279
guest_mode,
1280+
dark_mode,
12761281
devtools,
12771282
remote_debug,
12781283
enable_3d_apis,
@@ -1324,6 +1329,7 @@ def get_driver(
13241329
headless2,
13251330
incognito,
13261331
guest_mode,
1332+
dark_mode,
13271333
devtools,
13281334
remote_debug,
13291335
enable_3d_apis,
@@ -1379,6 +1385,7 @@ def get_remote_driver(
13791385
headless2,
13801386
incognito,
13811387
guest_mode,
1388+
dark_mode,
13821389
devtools,
13831390
remote_debug,
13841391
enable_3d_apis,
@@ -1499,6 +1506,7 @@ def get_remote_driver(
14991506
headless2,
15001507
incognito,
15011508
guest_mode,
1509+
dark_mode,
15021510
devtools,
15031511
remote_debug,
15041512
enable_3d_apis,
@@ -1688,6 +1696,7 @@ def get_remote_driver(
16881696
headless2,
16891697
incognito,
16901698
guest_mode,
1699+
dark_mode,
16911700
devtools,
16921701
remote_debug,
16931702
enable_3d_apis,
@@ -1809,6 +1818,7 @@ def get_remote_driver(
18091818
headless2,
18101819
incognito,
18111820
guest_mode,
1821+
dark_mode,
18121822
devtools,
18131823
remote_debug,
18141824
enable_3d_apis,
@@ -1928,6 +1938,7 @@ def get_local_driver(
19281938
headless2,
19291939
incognito,
19301940
guest_mode,
1941+
dark_mode,
19311942
devtools,
19321943
remote_debug,
19331944
enable_3d_apis,
@@ -2329,6 +2340,8 @@ def get_local_driver(
23292340
and not recorder_ext and not disable_csp and not proxy_auth
23302341
):
23312342
edge_options.add_argument("--guest")
2343+
if dark_mode:
2344+
edge_options.add_argument("--enable-features=WebContentsForceDark")
23322345
if headless2:
23332346
try:
23342347
if use_version == "latest" or int(use_version) >= 109:
@@ -2728,6 +2741,7 @@ def get_local_driver(
27282741
headless2,
27292742
incognito,
27302743
guest_mode,
2744+
dark_mode,
27312745
devtools,
27322746
remote_debug,
27332747
enable_3d_apis,
@@ -2783,6 +2797,7 @@ def get_local_driver(
27832797
headless2,
27842798
incognito,
27852799
guest_mode,
2800+
dark_mode,
27862801
devtools,
27872802
remote_debug,
27882803
enable_3d_apis,
@@ -3259,6 +3274,7 @@ def get_local_driver(
32593274
headless2,
32603275
incognito,
32613276
guest_mode,
3277+
dark_mode,
32623278
devtools,
32633279
remote_debug,
32643280
enable_3d_apis,

seleniumbase/fixtures/base_case.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3601,6 +3601,7 @@ def get_new_driver(
36013601
headless2=None,
36023602
incognito=None,
36033603
guest_mode=None,
3604+
dark_mode=None,
36043605
devtools=None,
36053606
remote_debug=None,
36063607
enable_3d_apis=None,
@@ -3654,7 +3655,8 @@ def get_new_driver(
36543655
disable_gpu - the option to enable Chrome's "Disable GPU" feature
36553656
headless2 - the option to use the newer headless mode (Chromium)
36563657
incognito - the option to enable Chrome's Incognito mode (Chrome)
3657-
guest - the option to enable Chrome's Guest mode (Chrome)
3658+
guest_mode - the option to enable Chrome's Guest mode (Chrome)
3659+
dark_mode - the option to enable Chrome's Dark mode (Chrome)
36583660
devtools - the option to open Chrome's DevTools on start (Chrome)
36593661
remote_debug - the option to enable Chrome's Remote Debugger
36603662
enable_3d_apis - the option to enable WebGL and 3D APIs (Chrome)
@@ -3763,6 +3765,8 @@ def get_new_driver(
37633765
incognito = self.incognito
37643766
if guest_mode is None:
37653767
guest_mode = self.guest_mode
3768+
if dark_mode is None:
3769+
dark_mode = self.dark_mode
37663770
if devtools is None:
37673771
devtools = self.devtools
37683772
if remote_debug is None:
@@ -3855,6 +3859,7 @@ def get_new_driver(
38553859
headless2=headless2,
38563860
incognito=incognito,
38573861
guest_mode=guest_mode,
3862+
dark_mode=dark_mode,
38583863
devtools=devtools,
38593864
remote_debug=remote_debug,
38603865
enable_3d_apis=enable_3d_apis,
@@ -13846,6 +13851,7 @@ def setUp(self, masterqa_mode=False):
1384613851
self.headless2 = sb_config.headless2
1384713852
self.incognito = sb_config.incognito
1384813853
self.guest_mode = sb_config.guest_mode
13854+
self.dark_mode = sb_config.dark_mode
1384913855
self.devtools = sb_config.devtools
1385013856
self.remote_debug = sb_config.remote_debug
1385113857
self._multithreaded = sb_config._multithreaded
@@ -14169,6 +14175,7 @@ def setUp(self, masterqa_mode=False):
1416914175
headless2=self.headless2,
1417014176
incognito=self.incognito,
1417114177
guest_mode=self.guest_mode,
14178+
dark_mode=self.dark_mode,
1417214179
devtools=self.devtools,
1417314180
remote_debug=self.remote_debug,
1417414181
enable_3d_apis=self.enable_3d_apis,

seleniumbase/plugins/driver_manager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def Driver(
8181
disable_gpu=None, # (DEPRECATED) - GPU is disabled if no "swiftshader".
8282
incognito=None, # Enable Chromium's Incognito mode.
8383
guest_mode=None, # Enable Chromium's Guest mode.
84+
dark_mode=None, # Enable Chromium's Dark mode.
8485
devtools=None, # Open Chromium's DevTools when the browser opens.
8586
remote_debug=None, # Enable Chrome's Debugger on "http://localhost:9222".
8687
enable_3d_apis=None, # Enable WebGL and 3D APIs.
@@ -226,6 +227,11 @@ def Driver(
226227
guest_mode = True
227228
else:
228229
guest_mode = False
230+
if dark_mode is None:
231+
if "--dark" in sys_argv:
232+
dark_mode = True
233+
else:
234+
dark_mode = False
229235
if devtools is None:
230236
if "--devtools" in sys_argv:
231237
devtools = True
@@ -423,6 +429,7 @@ def Driver(
423429
headless2=headless2,
424430
incognito=incognito,
425431
guest_mode=guest_mode,
432+
dark_mode=dark_mode,
426433
devtools=devtools,
427434
remote_debug=remote_debug,
428435
enable_3d_apis=enable_3d_apis,

seleniumbase/plugins/pytest_plugin.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def pytest_addoption(parser):
9696
--swiftshader (Use Chrome's "--use-gl=swiftshader" feature.)
9797
--incognito (Enable Chrome's Incognito mode.)
9898
--guest (Enable Chrome's Guest mode.)
99+
--dark (Enable Chrome's Dark mode.)
99100
--devtools (Open Chrome's DevTools when the browser opens.)
100101
--rs | --reuse-session (Reuse browser session for all tests.)
101102
--rcs | --reuse-class-session (Reuse session for tests in class.)
@@ -1082,6 +1083,15 @@ def pytest_addoption(parser):
10821083
default=False,
10831084
help="""Using this enables Chrome's Guest mode.""",
10841085
)
1086+
parser.addoption(
1087+
"--dark",
1088+
"--dark_mode",
1089+
"--dark-mode",
1090+
action="store_true",
1091+
dest="dark_mode",
1092+
default=False,
1093+
help="""Using this enables Chrome's Dark mode.""",
1094+
)
10851095
parser.addoption(
10861096
"--devtools",
10871097
"--open_devtools",
@@ -1523,6 +1533,7 @@ def pytest_configure(config):
15231533
sb_config.swiftshader = config.getoption("swiftshader")
15241534
sb_config.incognito = config.getoption("incognito")
15251535
sb_config.guest_mode = config.getoption("guest_mode")
1536+
sb_config.dark_mode = config.getoption("dark_mode")
15261537
sb_config.devtools = config.getoption("devtools")
15271538
sb_config.reuse_session = config.getoption("reuse_session")
15281539
sb_config.reuse_class_session = config.getoption("reuse_class_session")

seleniumbase/plugins/sb_manager.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def SB(
5050
uc_subprocess=None, # Use undetected-chromedriver as a subprocess.
5151
incognito=None, # Enable Chromium's Incognito mode.
5252
guest_mode=None, # Enable Chromium's Guest mode.
53+
dark_mode=None, # Enable Chromium's Dark mode.
5354
devtools=None, # Open Chromium's DevTools when the browser opens.
5455
remote_debug=None, # Enable Chrome's Debugger on "http://localhost:9222".
5556
enable_3d_apis=None, # Enable WebGL and 3D APIs.
@@ -290,6 +291,11 @@ def SB(
290291
guest_mode = True
291292
else:
292293
guest_mode = False
294+
if dark_mode is None:
295+
if "--dark" in sys_argv:
296+
dark_mode = True
297+
else:
298+
dark_mode = False
293299
if devtools is None:
294300
if "--devtools" in sys_argv:
295301
devtools = True
@@ -605,6 +611,7 @@ def SB(
605611
sb_config.user_agent = user_agent
606612
sb_config.incognito = incognito
607613
sb_config.guest_mode = guest_mode
614+
sb_config.dark_mode = dark_mode
608615
sb_config.devtools = devtools
609616
sb_config.mobile_emulator = is_mobile
610617
sb_config.device_metrics = device_metrics
@@ -703,6 +710,7 @@ def SB(
703710
sb.user_agent = sb_config.user_agent
704711
sb.incognito = sb_config.incognito
705712
sb.guest_mode = sb_config.guest_mode
713+
sb.dark_mode = sb_config.dark_mode
706714
sb.devtools = sb_config.devtools
707715
sb.binary_location = sb_config.binary_location
708716
sb.mobile_emulator = sb_config.mobile_emulator

seleniumbase/plugins/selenium_plugin.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class SeleniumBrowser(Plugin):
7474
--swiftshader (Use Chrome's "--use-gl=swiftshader" feature.)
7575
--incognito (Enable Chrome's Incognito mode.)
7676
--guest (Enable Chrome's Guest mode.)
77+
--dark (Enable Chrome's Dark mode.)
7778
--devtools (Open Chrome's DevTools when the browser opens.)
7879
--disable-beforeunload (Disable the "beforeunload" event on Chrome.)
7980
--window-size=WIDTH,HEIGHT (Set the browser's starting window size.)
@@ -800,6 +801,15 @@ def options(self, parser, env):
800801
default=False,
801802
help="""Using this enables Chrome's Guest mode.""",
802803
)
804+
parser.addoption(
805+
"--dark",
806+
"--dark_mode",
807+
"--dark-mode",
808+
action="store_true",
809+
dest="dark_mode",
810+
default=False,
811+
help="""Using this enables Chrome's Dark mode.""",
812+
)
803813
parser.addoption(
804814
"--devtools",
805815
"--open_devtools",
@@ -1125,6 +1135,7 @@ def beforeTest(self, test):
11251135
test.test.swiftshader = self.options.swiftshader
11261136
test.test.incognito = self.options.incognito
11271137
test.test.guest_mode = self.options.guest_mode
1138+
test.test.dark_mode = self.options.dark_mode
11281139
test.test.devtools = self.options.devtools
11291140
test.test._disable_beforeunload = self.options._disable_beforeunload
11301141
test.test.window_size = self.options.window_size

0 commit comments

Comments
 (0)