-
Notifications
You must be signed in to change notification settings - Fork 910
/
pytest_plugin.py
2407 lines (2346 loc) 路 92.8 KB
/
pytest_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""This is the pytest configuration file for setting test options."""
import colorama
import os
import pytest
import sys
import time
from seleniumbase import config as sb_config
from seleniumbase.config import settings
from seleniumbase.core import log_helper
from seleniumbase.fixtures import constants
from seleniumbase.fixtures import shared_utils
is_windows = shared_utils.is_windows()
python3_11_or_newer = False
if sys.version_info >= (3, 11):
python3_11_or_newer = True
py311_patch2 = constants.PatchPy311.PATCH
sys_argv = sys.argv
pytest_plugins = ["pytester"] # Adds the "testdir" fixture
def pytest_addoption(parser):
"""This plugin adds the following command-line options to pytest:
--browser=BROWSER (The web browser to use. Default: "chrome".)
--chrome (Shortcut for "--browser=chrome". Default.)
--edge (Shortcut for "--browser=edge".)
--firefox (Shortcut for "--browser=firefox".)
--safari (Shortcut for "--browser=safari".)
--settings-file=FILE (Override default SeleniumBase settings.)
--env=ENV (Set the test env. Access with "self.env" in tests.)
--account=STR (Set account. Access with "self.account" in tests.)
--data=STRING (Extra test data. Access with "self.data" in tests.)
--var1=STRING (Extra test data. Access with "self.var1" in tests.)
--var2=STRING (Extra test data. Access with "self.var2" in tests.)
--var3=STRING (Extra test data. Access with "self.var3" in tests.)
--variables=DICT (Extra test data. Access with "self.variables".)
--user-data-dir=DIR (Set the Chrome user data directory to use.)
--protocol=PROTOCOL (The Selenium Grid protocol: http|https.)
--server=SERVER (The Selenium Grid server/IP used for tests.)
--port=PORT (The Selenium Grid port used by the test server.)
--cap-file=FILE (The web browser's desired capabilities to use.)
--cap-string=STRING (The web browser's desired capabilities to use.)
--proxy=SERVER:PORT (Connect to a proxy server:port as tests are running)
--proxy=USERNAME:PASSWORD@SERVER:PORT (Use an authenticated proxy server)
--proxy-bypass-list=STRING (";"-separated hosts to bypass, Eg "*.foo.com")
--proxy-pac-url=URL (Connect to a proxy server using a PAC_URL.pac file.)
--proxy-pac-url=USERNAME:PASSWORD@URL (Authenticated proxy with PAC URL.)
--proxy-driver (If a driver download is needed, will use: --proxy=PROXY.)
--multi-proxy (Allow multiple authenticated proxies when multi-threaded.)
--agent=STRING (Modify the web browser's User-Agent string.)
--mobile (Use the mobile device emulator while running tests.)
--metrics=STRING (Set mobile metrics: "CSSWidth,CSSHeight,PixelRatio".)
--chromium-arg="ARG=N,ARG2" (Set Chromium args, ","-separated, no spaces.)
--firefox-arg="ARG=N,ARG2" (Set Firefox args, comma-separated, no spaces.)
--firefox-pref=SET (Set a Firefox preference:value set, comma-separated.)
--extension-zip=ZIP (Load a Chrome Extension .zip|.crx, comma-separated.)
--extension-dir=DIR (Load a Chrome Extension directory, comma-separated.)
--disable-features="F1,F2" (Disable features, comma-separated, no spaces.)
--binary-location=PATH (Set path of the Chromium browser binary to use.)
--driver-version=VER (Set the chromedriver or uc_driver version to use.)
--sjw (Skip JS Waits for readyState to be "complete" or Angular to load.)
--pls=PLS (Set pageLoadStrategy on Chrome: "normal", "eager", or "none".)
--headless (Run tests in headless mode. The default arg on Linux OS.)
--headless2 (Use the new headless mode, which supports extensions.)
--headed (Run tests in headed/GUI mode on Linux OS, where not default.)
--xvfb (Run tests using the Xvfb virtual display server on Linux OS.)
--locale=LOCALE_CODE (Set the Language Locale Code for the web browser.)
--interval=SECONDS (The autoplay interval for presentations & tour steps)
--start-page=URL (The starting URL for the web browser when tests begin.)
--archive-logs (Archive existing log files instead of deleting them.)
--archive-downloads (Archive old downloads instead of deleting them.)
--time-limit=SECONDS (Safely fail any test that exceeds the time limit.)
--slow (Slow down the automation. Faster than using Demo Mode.)
--demo (Slow down and visually see test actions as they occur.)
--demo-sleep=SECONDS (Set the wait time after Slow & Demo Mode actions.)
--highlights=NUM (Number of highlight animations for Demo Mode actions.)
--message-duration=SECONDS (The time length for Messenger alerts.)
--check-js (Check for JavaScript errors after page loads.)
--ad-block (Block some types of display ads from loading.)
--host-resolver-rules=RULES (Set host-resolver-rules, comma-separated.)
--block-images (Block images from loading during tests.)
--do-not-track (Indicate to websites that you don't want to be tracked.)
--verify-delay=SECONDS (The delay before MasterQA verification checks.)
--ee / --esc-end (Lets the user end the current test via the ESC key.)
--recorder (Enables the Recorder for turning browser actions into code.)
--rec-behave (Same as Recorder Mode, but also generates behave-gherkin.)
--rec-sleep (If the Recorder is enabled, also records self.sleep calls.)
--rec-print (If the Recorder is enabled, prints output after tests end.)
--disable-js (Disable JavaScript on websites. Pages might break!)
--disable-csp (Disable the Content Security Policy of websites.)
--disable-ws (Disable Web Security on Chromium-based browsers.)
--enable-ws (Enable Web Security on Chromium-based browsers.)
--enable-sync (Enable "Chrome Sync" on websites.)
--uc | --undetected (Use undetected-chromedriver to evade bot-detection.)
--uc-cdp-events (Capture CDP events when running in "--undetected" mode.)
--log-cdp ("goog:loggingPrefs", {"performance": "ALL", "browser": "ALL"})
--remote-debug (Sync to Chrome Remote Debugger chrome://inspect/#devices)
--ftrace | --final-trace (Debug Mode after each test. Don't use with CI!)
--dashboard (Enable the SeleniumBase Dashboard. Saved at: dashboard.html)
--dash-title=STRING (Set the title shown for the generated dashboard.)
--enable-3d-apis (Enables WebGL and 3D APIs.)
--swiftshader (Chrome "--use-gl=angle" / "--use-angle=swiftshader-webgl")
--incognito (Enable Chrome's Incognito mode.)
--guest (Enable Chrome's Guest mode.)
--dark (Enable Chrome's Dark mode.)
--devtools (Open Chrome's DevTools when the browser opens.)
--rs | --reuse-session (Reuse browser session for all tests.)
--rcs | --reuse-class-session (Reuse session for tests in class.)
--crumbs (Delete all cookies between tests reusing a session.)
--disable-beforeunload (Disable the "beforeunload" event on Chrome.)
--window-size=WIDTH,HEIGHT (Set the browser's starting window size.)
--maximize (Start tests with the browser window maximized.)
--screenshot (Save a screenshot at the end of each test.)
--no-screenshot (No screenshots saved unless tests directly ask it.)
--visual-baseline (Set the visual baseline for Visual/Layout tests.)
--wire (Use selenium-wire's webdriver for replacing selenium webdriver.)
--external-pdf (Set Chromium "plugins.always_open_pdf_externally":True.)
--timeout-multiplier=MULTIPLIER (Multiplies the default timeout values.)
--list-fail-page (After each failing test, list the URL of the failure.)
"""
c1 = ""
c2 = ""
c3 = ""
cr = ""
if "linux" not in sys.platform:
# This will be seen when typing "pytest --help" on the command line.
if is_windows and hasattr(colorama, "just_fix_windows_console"):
colorama.just_fix_windows_console()
else:
colorama.init(autoreset=True)
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
c3 = colorama.Fore.MAGENTA + colorama.Back.LIGHTYELLOW_EX
cr = colorama.Style.RESET_ALL
s_str = "SeleniumBase"
s_str = s_str.replace("SeleniumBase", c1 + "Selenium" + c2 + "Base" + cr)
s_str = s_str + cr + " " + c3 + "command-line options for pytest" + cr
parser = parser.getgroup("SeleniumBase", s_str)
parser.addoption(
"--browser",
action="store",
dest="browser",
type=str.lower,
choices=constants.ValidBrowsers.valid_browsers,
default=constants.Browser.GOOGLE_CHROME,
help="""Specifies the web browser to use. Default: Chrome.
Examples: (--browser=edge OR --browser=firefox)""",
)
parser.addoption(
"--chrome",
action="store_true",
dest="use_chrome",
default=False,
help="""Shortcut for --browser=chrome (Default)""",
)
parser.addoption(
"--edge",
action="store_true",
dest="use_edge",
default=False,
help="""Shortcut for --browser=edge""",
)
parser.addoption(
"--firefox",
action="store_true",
dest="use_firefox",
default=False,
help="""Shortcut for --browser=firefox""",
)
parser.addoption(
"--ie",
action="store_true",
dest="use_ie",
default=False,
help="""Shortcut for --browser=ie""",
)
parser.addoption(
"--safari",
action="store_true",
dest="use_safari",
default=False,
help="""Shortcut for --browser=safari""",
)
parser.addoption(
"--with-selenium",
action="store_true",
dest="with_selenium",
default=True,
help="""(DEPRECATED) Start tests with an open web browser.
(This is ALWAYS True now when importing BaseCase)""",
)
parser.addoption(
"--env",
action="store",
dest="environment",
type=str.lower,
choices=(
constants.Environment.QA,
constants.Environment.RC,
constants.Environment.STAGING,
constants.Environment.DEVELOP,
constants.Environment.PRODUCTION,
constants.Environment.PERFORMANCE,
constants.Environment.REPLICA,
constants.Environment.FEDRAMP,
constants.Environment.OFFLINE,
constants.Environment.ONLINE,
constants.Environment.MASTER,
constants.Environment.REMOTE,
constants.Environment.LEGACY,
constants.Environment.LOCAL,
constants.Environment.ALPHA,
constants.Environment.BETA,
constants.Environment.DEMO,
constants.Environment.GDPR,
constants.Environment.MAIN,
constants.Environment.TEST,
constants.Environment.GOV,
constants.Environment.NEW,
constants.Environment.OLD,
constants.Environment.UAT,
),
default=constants.Environment.TEST,
help="""This option sets a test env from a list of choices.
Access using "self.env" or "self.environment".""",
)
parser.addoption(
"--account",
dest="account",
default=None,
help="""This option sets a test account string.
In tests, use "self.account" to get the value.""",
)
parser.addoption(
"--data",
dest="data",
default=None,
help="Extra data to pass to tests from the command line.",
)
parser.addoption(
"--var1",
dest="var1",
default=None,
help="Extra data to pass to tests from the command line.",
)
parser.addoption(
"--var2",
dest="var2",
default=None,
help="Extra data to pass to tests from the command line.",
)
parser.addoption(
"--var3",
dest="var3",
default=None,
help="Extra data to pass to tests from the command line.",
)
parser.addoption(
"--variables",
dest="variables",
default=None,
help="""A var dict to pass to tests from the command line.
Example usage:
----------------------------------------------
Option: --variables='{"special":123}'
Access: self.variables["special"] # (123)
----------------------------------------------
Option: --variables='{"color":"red","num":42}'
Access: self.variables["color"] # ("red")
Access: self.variables["num"] # (42)
----------------------------------------------""",
)
parser.addoption(
"--cap_file",
"--cap-file",
dest="cap_file",
default=None,
help="""The file that stores browser desired capabilities
for BrowserStack, Sauce Labs, or other grids.""",
)
parser.addoption(
"--cap_string",
"--cap-string",
dest="cap_string",
default=None,
help="""The string that stores browser desired capabilities
for BrowserStack, Sauce Labs, or other grids.
Enclose cap-string in single quotes.
Enclose parameter keys in double quotes.
Example: --cap-string='{"name":"test1","v":"42"}'""",
)
parser.addoption(
"--settings_file",
"--settings-file",
"--settings",
action="store",
dest="settings_file",
default=None,
help="""The file that stores key/value pairs for
overriding values in the
seleniumbase/config/settings.py file.""",
)
parser.addoption(
"--user_data_dir",
"--user-data-dir",
dest="user_data_dir",
default=None,
help="""The Chrome User Data Directory to use. (Profile)
If the directory doesn't exist, it'll be created.""",
)
parser.addoption(
"--with-testing_base",
"--with-testing-base",
action="store_true",
dest="with_testing_base",
default=True,
help="""(DEPRECATED) - This option is always enabled now.
Use for saving logs & screenshots when tests fail.
The following options are now active by default
with --with-testing_base (which is always on now):
--with-screen_shots ,
--with-basic_test_info ,
--with-page_source
""",
)
parser.addoption(
"--log_path",
"--log-path",
dest="log_path",
default=constants.Logs.LATEST + "/",
help="""(DEPRECATED) - This value is NOT EDITABLE anymore.
Log files are saved to the "latest_logs/" folder.""",
)
parser.addoption(
"--archive_logs",
"--archive-logs",
action="store_true",
dest="archive_logs",
default=False,
help="Archive old log files instead of deleting them.",
)
parser.addoption(
"--archive_downloads",
"--archive-downloads",
action="store_true",
dest="archive_downloads",
default=False,
help="Archive old downloads instead of deleting them.",
)
parser.addoption(
"--sjw",
"--skip_js_waits",
"--skip-js-waits",
action="store_true",
dest="skip_js_waits",
default=False,
help="""Skip all calls to wait_for_ready_state_complete()
and wait_for_angularjs(), which are part of many
SeleniumBase methods for improving reliability.""",
)
parser.addoption(
"--with-db_reporting",
"--with-db-reporting",
action="store_true",
dest="with_db_reporting",
default=False,
help="Use to record test data in the MySQL database.",
)
parser.addoption(
"--database_env",
"--database-env",
action="store",
dest="database_env",
choices=(
constants.Environment.QA,
constants.Environment.RC,
constants.Environment.STAGING,
constants.Environment.DEVELOP,
constants.Environment.PRODUCTION,
constants.Environment.PERFORMANCE,
constants.Environment.REPLICA,
constants.Environment.FEDRAMP,
constants.Environment.OFFLINE,
constants.Environment.ONLINE,
constants.Environment.MASTER,
constants.Environment.REMOTE,
constants.Environment.LEGACY,
constants.Environment.LOCAL,
constants.Environment.ALPHA,
constants.Environment.BETA,
constants.Environment.DEMO,
constants.Environment.GDPR,
constants.Environment.MAIN,
constants.Environment.TEST,
constants.Environment.GOV,
constants.Environment.NEW,
constants.Environment.OLD,
constants.Environment.UAT,
),
default=constants.Environment.TEST,
help="The database environment to run the tests in.",
)
parser.addoption(
"--with-s3_logging",
"--with-s3-logging",
action="store_true",
dest="with_s3_logging",
default=False,
help="Use to save test log files in Amazon S3.",
)
parser.addoption(
"--with-screen_shots",
"--with-screen-shots",
action="store_true",
dest="with_screen_shots",
default=False,
help="""(DEPRECATED) - Screenshots are always saved now.
This option saves screenshots during test failures.
Screenshots are saved in the "latest_logs/" folder.
(Automatically on when using --with-testing_base)""",
)
parser.addoption(
"--with-basic_test_info",
"--with-basic-test-info",
action="store_true",
dest="with_basic_test_info",
default=False,
help="""(DEPRECATED) - Info files are always saved now.
This option saves basic test info on test failures.
These files are saved in the "latest_logs/" folder.
(Automatically on when using --with-testing_base)""",
)
parser.addoption(
"--with-page_source",
"--with-page-source",
action="store_true",
dest="with_page_source",
default=False,
help="""(DEPRECATED) - Page source is saved by default.
This option saves page source files on test failures.
(Automatically on when using --with-testing_base)""",
)
parser.addoption(
"--protocol",
action="store",
dest="protocol",
choices=(
constants.Protocol.HTTP,
constants.Protocol.HTTPS,
),
default=constants.Protocol.HTTP,
help="""Designates the Selenium Grid protocol to use.
Default: http.""",
)
parser.addoption(
"--server",
action="store",
dest="servername",
default="localhost",
help="""Designates the Selenium Grid server to use.
Use "127.0.0.1" to connect to a localhost Grid.
If unset or set to "localhost", Grid isn't used.
Default: "localhost".""",
)
parser.addoption(
"--port",
action="store",
dest="port",
default="4444",
help="""Designates the Selenium Grid port to use.
Default: 4444. (If 443, protocol becomes "https")""",
)
parser.addoption(
"--proxy",
"--proxy-server",
"--proxy-string",
action="store",
dest="proxy_string",
default=None,
help="""Designates the proxy server:port to use.
Format: servername:port. OR
username:password@servername:port OR
A dict key from proxy_list.PROXY_LIST
Default: None.""",
)
parser.addoption(
"--proxy-bypass-list",
"--proxy_bypass_list",
action="store",
dest="proxy_bypass_list",
default=None,
help="""Designates the hosts, domains, and/or IP addresses
to bypass when using a proxy server with "--proxy".
Format: A ";"-separated string.
Example usage:
pytest
--proxy="username:password@servername:port"
--proxy-bypass-list="*.foo.com;github.com"
pytest
--proxy="servername:port"
--proxy-bypass-list="127.0.0.1:8080"
Default: None.""",
)
parser.addoption(
"--proxy-pac-url",
"--pac-url",
action="store",
dest="proxy_pac_url",
default=None,
help="""Designates the proxy PAC URL to use.
Format: A URL string OR
A username:password@URL string
Default: None.""",
)
parser.addoption(
"--proxy-driver",
"--proxy_driver",
action="store_true",
dest="proxy_driver",
default=False,
help="""If a driver download is needed for tests,
uses proxy settings set via --proxy=PROXY.""",
)
parser.addoption(
"--multi-proxy",
"--multi_proxy",
action="store_true",
dest="multi_proxy",
default=False,
help="""If you need to run multi-threaded tests with
multiple proxies that require authentication,
set this to allow multiple configurations.""",
)
parser.addoption(
"--agent",
"--user-agent",
"--user_agent",
action="store",
dest="user_agent",
default=None,
help="""Designates the User-Agent for the browser to use.
Format: A string.
Default: None.""",
)
parser.addoption(
"--mobile",
"--mobile-emulator",
"--mobile_emulator",
action="store_true",
dest="mobile_emulator",
default=False,
help="""If this option is enabled, the mobile emulator
will be used while running tests.""",
)
parser.addoption(
"--metrics",
"--device-metrics",
"--device_metrics",
action="store",
dest="device_metrics",
default=None,
help="""Designates the three device metrics of the mobile
emulator: CSS Width, CSS Height, and Pixel-Ratio.
Format: A comma-separated string with the 3 values.
Examples: "375,734,5" or "411,731,3" or "390,715,3"
Default: None. (Will use default values if None)""",
)
parser.addoption(
"--chromium_arg",
"--chromium-arg",
action="store",
dest="chromium_arg",
default=None,
help="""Add a Chromium argument for Chrome/Edge browsers.
Format: A comma-separated list of Chromium args.
If an arg doesn't start with "--", that will be
added to the beginning of the arg automatically.
Default: None.""",
)
parser.addoption(
"--firefox_arg",
"--firefox-arg",
action="store",
dest="firefox_arg",
default=None,
help="""Add a Firefox argument for Firefox browser runs.
Format: A comma-separated list of Firefox args.
If an arg doesn't start with "--", that will be
added to the beginning of the arg automatically.
Default: None.""",
)
parser.addoption(
"--firefox_pref",
"--firefox-pref",
action="store",
dest="firefox_pref",
default=None,
help="""Set a Firefox preference:value combination.
Format: A comma-separated list of pref:value items.
Example usage:
--firefox-pref="browser.formfill.enable:True"
--firefox-pref="pdfjs.disabled:False"
--firefox-pref="abc.def.xyz:42,hello.world:text"
Boolean and integer values to the right of the ":"
will be automatically converted into proper format.
If there's no ":" in the string, then True is used.
Default: None.""",
)
parser.addoption(
"--extension_zip",
"--extension-zip",
"--crx",
action="store",
dest="extension_zip",
default=None,
help="""Designates the Chrome Extension ZIP file to load.
Format: A comma-separated list of .zip or .crx files
containing the Chrome extensions to load.
Default: None.""",
)
parser.addoption(
"--extension_dir",
"--extension-dir",
action="store",
dest="extension_dir",
default=None,
help="""Designates the Chrome Extension folder to load.
Format: A directory containing the Chrome extension.
(Can also be a comma-separated list of directories.)
Default: None.""",
)
parser.addoption(
"--disable_features",
"--disable-features",
action="store",
dest="disable_features",
default=None,
help="""Disable Chromium features from Chrome/Edge browsers.
Format: A comma-separated list of Chromium features.
Default: None.""",
)
parser.addoption(
"--binary_location",
"--binary-location",
action="store",
dest="binary_location",
default=None,
help="""Sets the path of the Chromium browser binary to use.
Uses the default location if not os.path.exists(PATH)""",
)
parser.addoption(
"--driver_version",
"--driver-version",
action="store",
dest="driver_version",
default=None,
help="""Setting this overrides the default driver version,
which is set to match the detected browser version.
Major version only. Example: "--driver-version=114"
(Only chromedriver and uc_driver are affected.)""",
)
parser.addoption(
"--pls",
"--page_load_strategy",
"--page-load-strategy",
action="store",
dest="page_load_strategy",
type=str.lower,
choices=(
constants.PageLoadStrategy.NORMAL,
constants.PageLoadStrategy.EAGER,
constants.PageLoadStrategy.NONE,
),
default=None,
help="""This option sets Chrome's pageLoadStrategy.
List of choices: "normal", "eager", "none".""",
)
parser.addoption(
"--headless",
action="store_true",
dest="headless",
default=False,
help="""Using this option activates headless mode,
which is required on headless machines
UNLESS using a virtual display with Xvfb.
Default: False on Mac/Windows. True on Linux.""",
)
parser.addoption(
"--headless2",
action="store_true",
dest="headless2",
default=False,
help="""This option activates the new headless mode,
which supports Chromium extensions, and more,
but is slower than the standard headless mode.""",
)
parser.addoption(
"--headed",
"--gui",
action="store_true",
dest="headed",
default=False,
help="""Using this makes Webdriver run web browsers with
a GUI when running tests on Linux machines.
(The default setting on Linux is headless.)
(The default setting on Mac or Windows is headed.)""",
)
parser.addoption(
"--xvfb",
action="store_true",
dest="xvfb",
default=False,
help="""Using this makes tests run headlessly using Xvfb
instead of the browser's built-in headless mode.
When using "--xvfb", the "--headless" option
will no longer be enabled by default on Linux.
Default: False. (Linux-ONLY!)""",
)
parser.addoption(
"--locale_code",
"--locale-code",
"--locale",
action="store",
dest="locale_code",
default=None,
help="""Designates the Locale Code for the web browser.
A Locale is a specific version of a spoken Language.
The Locale alters visible text on supported websites.
See: https://seleniumbase.io/help_docs/locale_codes/
Default: None. (The web browser's default mode.)""",
)
parser.addoption(
"--interval",
action="store",
dest="interval",
default=None,
help="""This globally overrides the default interval,
(in seconds), of features that include autoplay
functionality, such as tours and presentations.
Overrides from methods take priority over this.
(Headless Mode skips tours and presentations.)""",
)
parser.addoption(
"--start_page",
"--start-page",
"--url",
action="store",
dest="start_page",
default=None,
help="""Designates the starting URL for the web browser
when each test begins.
Default: None.""",
)
parser.addoption(
"--is_pytest",
"--is-pytest",
action="store_true",
dest="is_pytest",
default=True,
help="""This is used by the BaseCase class to tell apart
pytest runs from nosetest runs. (Automatic)""",
)
parser.addoption(
"--all-scripts",
"--all_scripts",
action="store_true",
dest="all_scripts",
default=False,
help="""Use this to run `SB()`, `DriverContext()` and
`Driver()` scripts that are discovered during
the pytest collection phase.""",
)
parser.addoption(
"--time_limit",
"--time-limit",
"--timelimit",
action="store",
dest="time_limit",
default=None,
help="""Use this to set a time limit per test, in seconds.
If a test runs beyond the limit, it fails.""",
)
parser.addoption(
"--slow_mode",
"--slow-mode",
"--slowmo",
"--slow",
action="store_true",
dest="slow_mode",
default=False,
help="""Using this slows down the automation.""",
)
parser.addoption(
"--demo_mode",
"--demo-mode",
"--demo",
action="store_true",
dest="demo_mode",
default=False,
help="""Using this slows down the automation and lets you
visually see what the tests are actually doing.""",
)
parser.addoption(
"--demo_sleep",
"--demo-sleep",
action="store",
dest="demo_sleep",
default=None,
help="""Setting this overrides the Demo Mode sleep
time that happens after browser actions.""",
)
parser.addoption(
"--highlights",
action="store",
dest="highlights",
default=None,
help="""Setting this overrides the default number of
highlight animation loops to have per call.""",
)
parser.addoption(
"--message_duration",
"--message-duration",
action="store",
dest="message_duration",
default=None,
help="""Setting this overrides the default time that
messenger notifications remain visible when
reaching assert statements during Demo Mode.""",
)
parser.addoption(
"--check_js",
"--check-js",
action="store_true",
dest="js_checking_on",
default=False,
help="""The option to check for JavaScript errors after
every page load.""",
)
parser.addoption(
"--adblock",
"--ad_block",
"--ad-block",
"--block_ads",
"--block-ads",
action="store_true",
dest="ad_block_on",
default=False,
help="""Using this makes WebDriver block display ads
that are defined in ad_block_list.AD_BLOCK_LIST.""",
)
parser.addoption(
"--host_resolver_rules",
"--host-resolver-rules",
action="store",
dest="host_resolver_rules",
default=None,
help="""Use this option to set "host-resolver-rules".
This lets you re-map traffic from any domain.
Eg. "MAP www.google-analytics.com 0.0.0.0".
Eg. "MAP * ~NOTFOUND , EXCLUDE myproxy".
Eg. "MAP * 0.0.0.0 , EXCLUDE 127.0.0.1".
Eg. "MAP *.google.com myproxy".
Find more examples on these pages:
(https://www.electronjs.org/docs/
latest/api/command-line-switches)
(https://www.chromium.org/developers/
design-documents/network-stack/socks-proxy/)
Use comma-separation for multiple host rules.""",
)
parser.addoption(
"--block_images",
"--block-images",
action="store_true",
dest="block_images",
default=False,
help="""Using this makes WebDriver block images from
loading on web pages during tests.""",
)
parser.addoption(
"--do_not_track",
"--do-not-track",
action="store_true",
dest="do_not_track",
default=False,
help="""Indicate to websites that you don't want to be
tracked. The browser will send an extra HTTP
header each time it requests a web page.
https://support.google.com/chrome/answer/2790761""",
)
parser.addoption(
"--verify_delay",
"--verify-delay",
action="store",
dest="verify_delay",
default=None,
help="""Setting this overrides the default wait time
before each MasterQA verification pop-up.""",
)
parser.addoption(
"--esc-end",
"--esc_end",
"--ee",
action="store_true",
dest="esc_end",
default=False,
help="""End the current test early via the ESC key.
The test will be marked as skipped.""",
)
parser.addoption(
"--recorder",
"--record",
"--rec",
"--codegen",
action="store_true",
dest="recorder_mode",
default=False,
help="""Using this enables the SeleniumBase Recorder,
which records browser actions for converting
into SeleniumBase scripts.""",
)
parser.addoption(
"--rec-behave",
"--rec-gherkin",
action="store_true",
dest="rec_behave",
default=False,
help="""Not only enables the SeleniumBase Recorder,
but also saves recorded actions into the
behave-gerkin format, which includes a
feature file, an imported steps file,
and the environment.py file.""",
)
parser.addoption(
"--rec-sleep",
"--record-sleep",
action="store_true",
dest="record_sleep",
default=False,
help="""If Recorder Mode is enabled,
records sleep(seconds) calls.""",
)
parser.addoption(
"--rec-print",
action="store_true",
dest="rec_print",
default=False,
help="""If Recorder Mode is enabled,
prints output after tests end.""",
)
parser.addoption(
"--disable_js",
"--disable-js",
action="store_true",
dest="disable_js",
default=False,
help="""The option to disable JavaScript on web pages.
Warning: Most web pages will stop working!""",
)
parser.addoption(
"--disable_csp",
"--disable-csp",
"--no_csp",
"--no-csp",
"--dcsp",
action="store_true",
dest="disable_csp",
default=False,
help="""Using this disables the Content Security Policy of
websites, which may interfere with some features of
SeleniumBase, such as loading custom JavaScript
libraries for various testing actions.
Setting this to True (--disable-csp) overrides the
value set in seleniumbase/config/settings.py""",
)
parser.addoption(
"--disable_ws",
"--disable-ws",
"--disable-web-security",
action="store_true",
dest="disable_ws",
default=False,
help="""Using this disables the "Web Security" feature of
Chrome and Chromium-based browsers such as Edge.""",
)
parser.addoption(
"--enable_ws",
"--enable-ws",
"--enable-web-security",
action="store_true",
dest="enable_ws",
default=False,
help="""Using this enables the "Web Security" feature of
Chrome and Chromium-based browsers such as Edge.""",
)
parser.addoption(
"--enable_sync",
"--enable-sync",
action="store_true",
dest="enable_sync",
default=False,