seleniumbase 4.41.3__py3-none-any.whl → 4.45.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. sbase/steps.py +9 -0
  2. seleniumbase/__version__.py +1 -1
  3. seleniumbase/behave/behave_helper.py +2 -0
  4. seleniumbase/behave/behave_sb.py +21 -8
  5. seleniumbase/common/decorators.py +3 -1
  6. seleniumbase/console_scripts/run.py +1 -0
  7. seleniumbase/console_scripts/sb_caseplans.py +3 -4
  8. seleniumbase/console_scripts/sb_install.py +142 -11
  9. seleniumbase/console_scripts/sb_mkchart.py +1 -2
  10. seleniumbase/console_scripts/sb_mkdir.py +99 -29
  11. seleniumbase/console_scripts/sb_mkfile.py +1 -2
  12. seleniumbase/console_scripts/sb_mkpres.py +1 -2
  13. seleniumbase/console_scripts/sb_mkrec.py +26 -2
  14. seleniumbase/console_scripts/sb_objectify.py +4 -5
  15. seleniumbase/console_scripts/sb_print.py +1 -1
  16. seleniumbase/console_scripts/sb_recorder.py +40 -3
  17. seleniumbase/core/browser_launcher.py +474 -151
  18. seleniumbase/core/detect_b_ver.py +258 -16
  19. seleniumbase/core/log_helper.py +15 -21
  20. seleniumbase/core/mysql.py +1 -1
  21. seleniumbase/core/recorder_helper.py +3 -0
  22. seleniumbase/core/report_helper.py +9 -12
  23. seleniumbase/core/sb_cdp.py +734 -215
  24. seleniumbase/core/sb_driver.py +46 -5
  25. seleniumbase/core/session_helper.py +2 -4
  26. seleniumbase/core/tour_helper.py +1 -2
  27. seleniumbase/drivers/atlas_drivers/__init__.py +0 -0
  28. seleniumbase/drivers/brave_drivers/__init__.py +0 -0
  29. seleniumbase/drivers/chromium_drivers/__init__.py +0 -0
  30. seleniumbase/drivers/comet_drivers/__init__.py +0 -0
  31. seleniumbase/drivers/opera_drivers/__init__.py +0 -0
  32. seleniumbase/fixtures/base_case.py +448 -251
  33. seleniumbase/fixtures/constants.py +36 -9
  34. seleniumbase/fixtures/js_utils.py +77 -18
  35. seleniumbase/fixtures/page_actions.py +41 -13
  36. seleniumbase/fixtures/page_utils.py +19 -12
  37. seleniumbase/fixtures/shared_utils.py +64 -6
  38. seleniumbase/masterqa/master_qa.py +16 -2
  39. seleniumbase/plugins/base_plugin.py +8 -0
  40. seleniumbase/plugins/basic_test_info.py +2 -3
  41. seleniumbase/plugins/driver_manager.py +131 -5
  42. seleniumbase/plugins/page_source.py +2 -3
  43. seleniumbase/plugins/pytest_plugin.py +244 -79
  44. seleniumbase/plugins/sb_manager.py +143 -20
  45. seleniumbase/plugins/selenium_plugin.py +144 -12
  46. seleniumbase/translate/translator.py +2 -3
  47. seleniumbase/undetected/__init__.py +17 -13
  48. seleniumbase/undetected/cdp.py +1 -12
  49. seleniumbase/undetected/cdp_driver/browser.py +330 -129
  50. seleniumbase/undetected/cdp_driver/cdp_util.py +328 -61
  51. seleniumbase/undetected/cdp_driver/config.py +110 -14
  52. seleniumbase/undetected/cdp_driver/connection.py +18 -48
  53. seleniumbase/undetected/cdp_driver/element.py +105 -33
  54. seleniumbase/undetected/cdp_driver/tab.py +414 -39
  55. seleniumbase/utilities/selenium_grid/download_selenium_server.py +1 -1
  56. seleniumbase/utilities/selenium_grid/grid_hub.py +1 -2
  57. seleniumbase/utilities/selenium_grid/grid_node.py +2 -3
  58. seleniumbase/utilities/selenium_ide/convert_ide.py +2 -3
  59. {seleniumbase-4.41.3.dist-info → seleniumbase-4.45.10.dist-info}/METADATA +193 -166
  60. {seleniumbase-4.41.3.dist-info → seleniumbase-4.45.10.dist-info}/RECORD +64 -59
  61. {seleniumbase-4.41.3.dist-info → seleniumbase-4.45.10.dist-info}/licenses/LICENSE +1 -1
  62. {seleniumbase-4.41.3.dist-info → seleniumbase-4.45.10.dist-info}/WHEEL +0 -0
  63. {seleniumbase-4.41.3.dist-info → seleniumbase-4.45.10.dist-info}/entry_points.txt +0 -0
  64. {seleniumbase-4.41.3.dist-info → seleniumbase-4.45.10.dist-info}/top_level.txt +0 -0
@@ -10,13 +10,13 @@ Example -->
10
10
  ```python
11
11
  from seleniumbase import SB
12
12
 
13
- with SB(uc=True) as sb: # Many args! Eg. SB(browser="edge")
14
- sb.open("https://google.com/ncr")
15
- sb.type('[name="q"]', "SeleniumBase on GitHub\n")
16
- sb.click('a[href*="github.com/seleniumbase"]')
17
- sb.highlight("div.Layout-main")
18
- sb.highlight("div.Layout-sidebar")
19
- sb.sleep(0.5)
13
+ with SB(uc=True, test=True) as sb:
14
+ url = "https://google.com/ncr"
15
+ sb.activate_cdp_mode(url)
16
+ sb.type('[title="Search"]', "SeleniumBase GitHub page")
17
+ sb.click("div:not([jsname]) > * > input")
18
+ sb.sleep(2)
19
+ print(sb.get_page_title())
20
20
  ```
21
21
 
22
22
  # (The browser exits automatically after the "with" block ends.)
@@ -123,6 +123,7 @@ def SB(
123
123
  wfa=None, # Shortcut / Duplicate of "wait_for_angularjs".
124
124
  cft=None, # Use "Chrome for Testing"
125
125
  chs=None, # Use "Chrome-Headless-Shell"
126
+ use_chromium=None, # Use base "Chromium"
126
127
  save_screenshot=None, # Save a screenshot at the end of each test.
127
128
  no_screenshot=None, # No screenshots saved unless tests directly ask it.
128
129
  page_load_strategy=None, # Set Chrome PLS to "normal", "eager", or "none".
@@ -144,14 +145,13 @@ def SB(
144
145
  .. code-block:: python
145
146
  from seleniumbase import SB
146
147
 
147
- with SB() as sb: # Many args! Eg. SB(browser="edge")
148
- sb.open("https://google.com/ncr")
149
- sb.type('[name="q"]', "SeleniumBase on GitHub")
150
- sb.submit('[name="q"]')
151
- sb.click('a[href*="github.com/seleniumbase"]')
152
- sb.highlight("div.Layout-main")
153
- sb.highlight("div.Layout-sidebar")
154
- sb.sleep(0.5)
148
+ with SB(uc=True, test=True) as sb:
149
+ url = "https://google.com/ncr"
150
+ sb.activate_cdp_mode(url)
151
+ sb.type('[title="Search"]', "SeleniumBase GitHub page")
152
+ sb.click("div:not([jsname]) > * > input")
153
+ sb.sleep(2)
154
+ print(sb.get_page_title())
155
155
 
156
156
  Optional Parameters:
157
157
  --------------------
@@ -267,6 +267,7 @@ def SB(
267
267
  import traceback
268
268
  from seleniumbase import config as sb_config
269
269
  from seleniumbase.config import settings
270
+ from seleniumbase.core import detect_b_ver
270
271
  from seleniumbase.fixtures import constants
271
272
  from seleniumbase.fixtures import shared_utils
272
273
 
@@ -334,10 +335,37 @@ def SB(
334
335
  raise_test_failure = True # Exit on first error or failed test.
335
336
  else:
336
337
  raise_test_failure = False
338
+ sb_config._browser_shortcut = None
339
+ sb_config._cdp_browser = None
340
+ sb_config._cdp_bin_loc = None
337
341
  browser_changes = 0
338
342
  browser_set = None
339
343
  browser_text = None
340
344
  browser_list = []
345
+ # Check if binary-location in options
346
+ bin_loc_in_options = False
347
+ if (
348
+ binary_location
349
+ and len(str(binary_location)) > 5
350
+ and os.path.exists(str(binary_location))
351
+ ):
352
+ bin_loc_in_options = True
353
+ else:
354
+ for arg in sys_argv:
355
+ if arg in ["--binary-location", "--binary_location", "--bl"]:
356
+ bin_loc_in_options = True
357
+ if (
358
+ browser
359
+ and browser in constants.ChromiumSubs.chromium_subs
360
+ and not bin_loc_in_options
361
+ ):
362
+ bin_loc = detect_b_ver.get_binary_location(browser)
363
+ if bin_loc and os.path.exists(bin_loc):
364
+ if browser in bin_loc.lower().split("/")[-1].split("\\")[-1]:
365
+ sb_config._cdp_browser = browser
366
+ sb_config._cdp_bin_loc = bin_loc
367
+ binary_location = bin_loc
368
+ bin_loc_in_options = True
341
369
  # As a shortcut, you can use "--edge" instead of "--browser=edge", etc,
342
370
  # but you can only specify one default browser for tests. (Default: chrome)
343
371
  if "--browser=chrome" in sys_argv or "--browser chrome" in sys_argv:
@@ -364,6 +392,46 @@ def SB(
364
392
  browser_changes += 1
365
393
  browser_set = "remote"
366
394
  browser_list.append("--browser=remote")
395
+ if "--browser=opera" in sys_argv or "--browser opera" in sys_argv:
396
+ if not bin_loc_in_options:
397
+ bin_loc = detect_b_ver.get_binary_location("opera")
398
+ if os.path.exists(bin_loc):
399
+ browser_changes += 1
400
+ browser_set = "opera"
401
+ sb_config._browser_shortcut = "opera"
402
+ sb_config._cdp_browser = "opera"
403
+ sb_config._cdp_bin_loc = bin_loc
404
+ browser_list.append("--browser=opera")
405
+ if "--browser=brave" in sys_argv or "--browser brave" in sys_argv:
406
+ if not bin_loc_in_options:
407
+ bin_loc = detect_b_ver.get_binary_location("brave")
408
+ if os.path.exists(bin_loc):
409
+ browser_changes += 1
410
+ browser_set = "brave"
411
+ sb_config._browser_shortcut = "brave"
412
+ sb_config._cdp_browser = "brave"
413
+ sb_config._cdp_bin_loc = bin_loc
414
+ browser_list.append("--browser=brave")
415
+ if "--browser=comet" in sys_argv or "--browser comet" in sys_argv:
416
+ if not bin_loc_in_options:
417
+ bin_loc = detect_b_ver.get_binary_location("comet")
418
+ if os.path.exists(bin_loc):
419
+ browser_changes += 1
420
+ browser_set = "comet"
421
+ sb_config._browser_shortcut = "comet"
422
+ sb_config._cdp_browser = "comet"
423
+ sb_config._cdp_bin_loc = bin_loc
424
+ browser_list.append("--browser=comet")
425
+ if "--browser=atlas" in sys_argv or "--browser atlas" in sys_argv:
426
+ if not bin_loc_in_options:
427
+ bin_loc = detect_b_ver.get_binary_location("atlas")
428
+ if os.path.exists(bin_loc):
429
+ browser_changes += 1
430
+ browser_set = "atlas"
431
+ sb_config._browser_shortcut = "atlas"
432
+ sb_config._cdp_browser = "atlas"
433
+ sb_config._cdp_bin_loc = bin_loc
434
+ browser_list.append("--browser=atlas")
367
435
  browser_text = browser_set
368
436
  if "--chrome" in sys_argv and not browser_set == "chrome":
369
437
  browser_changes += 1
@@ -390,6 +458,46 @@ def SB(
390
458
  browser_text = "safari"
391
459
  sb_config._browser_shortcut = "safari"
392
460
  browser_list.append("--safari")
461
+ if "--opera" in sys_argv and not browser_set == "opera":
462
+ if not bin_loc_in_options:
463
+ bin_loc = detect_b_ver.get_binary_location("opera")
464
+ if os.path.exists(bin_loc):
465
+ browser_changes += 1
466
+ browser_text = "opera"
467
+ sb_config._browser_shortcut = "opera"
468
+ sb_config._cdp_browser = "opera"
469
+ sb_config._cdp_bin_loc = bin_loc
470
+ browser_list.append("--opera")
471
+ if "--brave" in sys_argv and not browser_set == "brave":
472
+ if not bin_loc_in_options:
473
+ bin_loc = detect_b_ver.get_binary_location("brave")
474
+ if os.path.exists(bin_loc):
475
+ browser_changes += 1
476
+ browser_text = "brave"
477
+ sb_config._browser_shortcut = "brave"
478
+ sb_config._cdp_browser = "brave"
479
+ sb_config._cdp_bin_loc = bin_loc
480
+ browser_list.append("--brave")
481
+ if "--comet" in sys_argv and not browser_set == "comet":
482
+ if not bin_loc_in_options:
483
+ bin_loc = detect_b_ver.get_binary_location("comet")
484
+ if os.path.exists(bin_loc):
485
+ browser_changes += 1
486
+ browser_text = "comet"
487
+ sb_config._browser_shortcut = "comet"
488
+ sb_config._cdp_browser = "comet"
489
+ sb_config._cdp_bin_loc = bin_loc
490
+ browser_list.append("--comet")
491
+ if "--atlas" in sys_argv and not browser_set == "atlas":
492
+ if not bin_loc_in_options:
493
+ bin_loc = detect_b_ver.get_binary_location("atlas")
494
+ if os.path.exists(bin_loc):
495
+ browser_changes += 1
496
+ browser_text = "atlas"
497
+ sb_config._browser_shortcut = "atlas"
498
+ sb_config._cdp_browser = "atlas"
499
+ sb_config._cdp_bin_loc = bin_loc
500
+ browser_list.append("--atlas")
393
501
  if browser_changes > 1:
394
502
  message = "\n\n TOO MANY browser types were entered!"
395
503
  message += "\n There were %s found:\n > %s" % (
@@ -592,11 +700,15 @@ def SB(
592
700
  if arg.startswith("--bl="):
593
701
  binary_location = arg.split("--bl=")[1]
594
702
  break
595
- if cft and not binary_location:
703
+ if use_chromium and not binary_location:
704
+ binary_location = "_chromium_"
705
+ elif cft and not binary_location:
596
706
  binary_location = "cft"
597
707
  elif chs and not binary_location:
598
708
  binary_location = "chs"
599
- if "--cft" in sys_argv and not binary_location:
709
+ if "--use-chromium" in sys_argv and not binary_location:
710
+ binary_location = "_chromium_"
711
+ elif "--cft" in sys_argv and not binary_location:
600
712
  binary_location = "cft"
601
713
  elif "--chs" in sys_argv and not binary_location:
602
714
  binary_location = "chs"
@@ -692,9 +804,12 @@ def SB(
692
804
  uc_cdp_events = True
693
805
  else:
694
806
  uc_cdp_events = False
695
- if undetectable and browser != "chrome":
807
+ if (
808
+ undetectable
809
+ and browser not in ["chrome", "opera", "brave", "comet", "atlas"]
810
+ ):
696
811
  message = (
697
- '\n Undetected-Chromedriver Mode ONLY supports Chrome!'
812
+ '\n Undetected-Chromedriver Mode ONLY supports Chromium browsers!'
698
813
  '\n ("uc=True" / "undetectable=True" / "--uc")'
699
814
  '\n (Your browser choice was: "%s".)'
700
815
  '\n (Will use "%s" without UC Mode.)\n' % (browser, browser)
@@ -720,7 +835,7 @@ def SB(
720
835
  if headless2 and browser == "firefox":
721
836
  headless2 = False # Only for Chromium browsers
722
837
  headless = True # Firefox has regular headless
723
- elif browser not in ["chrome", "edge"]:
838
+ elif browser not in ["chrome", "edge", "opera", "brave", "comet", "atlas"]:
724
839
  headless2 = False # Only for Chromium browsers
725
840
  if not headless and not headless2:
726
841
  headed = True
@@ -1019,6 +1134,8 @@ def SB(
1019
1134
 
1020
1135
  sb_config.with_testing_base = with_testing_base
1021
1136
  sb_config.browser = browser
1137
+ if sb_config._browser_shortcut:
1138
+ sb_config.browser = sb_config._browser_shortcut
1022
1139
  if not hasattr(sb_config, "is_behave"):
1023
1140
  sb_config.is_behave = False
1024
1141
  if not hasattr(sb_config, "is_pytest"):
@@ -1082,6 +1199,8 @@ def SB(
1082
1199
  sb_config.save_screenshot = save_screenshot
1083
1200
  sb_config.no_screenshot = no_screenshot
1084
1201
  sb_config.binary_location = binary_location
1202
+ if hasattr(sb_config, "_cdp_bin_loc") and sb_config._cdp_bin_loc:
1203
+ sb_config.binary_location = sb_config._cdp_bin_loc
1085
1204
  sb_config.driver_version = driver_version
1086
1205
  sb_config.page_load_strategy = page_load_strategy
1087
1206
  sb_config.timeout_multiplier = timeout_multiplier
@@ -1125,6 +1244,10 @@ def SB(
1125
1244
  sb_config.interval = interval
1126
1245
  sb_config.cap_file = cap_file
1127
1246
  sb_config.cap_string = cap_string
1247
+ if sb_config.browser in constants.ChromiumSubs.chromium_subs:
1248
+ if not sb_config.binary_location:
1249
+ sb_config.browser = "chrome" # Still uses chromedriver
1250
+ sb_config._browser_shortcut = sb_config.browser
1128
1251
 
1129
1252
  sb = BaseCase()
1130
1253
  sb.with_testing_base = sb_config.with_testing_base
@@ -1,9 +1,11 @@
1
1
  """Selenium Plugin for SeleniumBase tests that run with pynose / nosetests"""
2
+ import os
2
3
  import sys
3
4
  from contextlib import suppress
4
5
  from nose.plugins import Plugin
5
6
  from seleniumbase import config as sb_config
6
7
  from seleniumbase.config import settings
8
+ from seleniumbase.core import detect_b_ver
7
9
  from seleniumbase.core import proxy_helper
8
10
  from seleniumbase.fixtures import constants
9
11
  from seleniumbase.fixtures import shared_utils
@@ -16,6 +18,11 @@ class SeleniumBrowser(Plugin):
16
18
  --edge (Shortcut for "--browser=edge".)
17
19
  --firefox (Shortcut for "--browser=firefox".)
18
20
  --safari (Shortcut for "--browser=safari".)
21
+ --opera (Shortcut for "--browser=opera".)
22
+ --brave (Shortcut for "--browser=brave".)
23
+ --comet (Shortcut for "--browser=comet".)
24
+ --atlas (Shortcut for "--browser=atlas".)
25
+ --use-chromium (Shortcut for using base `Chromium`)
19
26
  --cft (Shortcut for using `Chrome for Testing`)
20
27
  --chs (Shortcut for using `Chrome-Headless-Shell`)
21
28
  --user-data-dir=DIR (Set the Chrome user data directory to use.)
@@ -146,6 +153,41 @@ class SeleniumBrowser(Plugin):
146
153
  default=False,
147
154
  help="""Shortcut for --browser=safari""",
148
155
  )
156
+ parser.addoption(
157
+ "--opera",
158
+ action="store_true",
159
+ dest="use_opera",
160
+ default=False,
161
+ help="""Shortcut for --browser=opera""",
162
+ )
163
+ parser.addoption(
164
+ "--brave",
165
+ action="store_true",
166
+ dest="use_brave",
167
+ default=False,
168
+ help="""Shortcut for --browser=brave""",
169
+ )
170
+ parser.addoption(
171
+ "--comet",
172
+ action="store_true",
173
+ dest="use_comet",
174
+ default=False,
175
+ help="""Shortcut for --browser=comet""",
176
+ )
177
+ parser.addoption(
178
+ "--atlas",
179
+ action="store_true",
180
+ dest="use_atlas",
181
+ default=False,
182
+ help="""Shortcut for --browser=atlas""",
183
+ )
184
+ parser.addoption(
185
+ "--use-chromium",
186
+ action="store_true",
187
+ dest="use_chromium",
188
+ default=False,
189
+ help="""Shortcut for using base `Chromium`""",
190
+ )
149
191
  parser.addoption(
150
192
  "--cft",
151
193
  action="store_true",
@@ -333,7 +375,7 @@ class SeleniumBrowser(Plugin):
333
375
  help="""Designates the three device metrics of the mobile
334
376
  emulator: CSS Width, CSS Height, and Pixel-Ratio.
335
377
  Format: A comma-separated string with the 3 values.
336
- Examples: "375,734,5" or "411,731,3" or "390,715,3"
378
+ Examples: "375,734,5" or "412,732,3" or "390,715,3"
337
379
  Default: None. (Will use default values if None)""",
338
380
  )
339
381
  parser.addoption(
@@ -1057,6 +1099,11 @@ class SeleniumBrowser(Plugin):
1057
1099
  browser_set = None
1058
1100
  browser_text = None
1059
1101
  browser_list = []
1102
+ # Check if binary-location in options
1103
+ bin_loc_in_options = False
1104
+ for arg in sys_argv:
1105
+ if arg in ["--binary-location", "--binary_location", "--bl"]:
1106
+ bin_loc_in_options = True
1060
1107
  if "--browser=chrome" in sys_argv or "--browser chrome" in sys_argv:
1061
1108
  browser_changes += 1
1062
1109
  browser_set = "chrome"
@@ -1081,6 +1128,46 @@ class SeleniumBrowser(Plugin):
1081
1128
  browser_changes += 1
1082
1129
  browser_set = "remote"
1083
1130
  browser_list.append("--browser=remote")
1131
+ if "--browser=opera" in sys_argv or "--browser opera" in sys_argv:
1132
+ if not bin_loc_in_options:
1133
+ bin_loc = detect_b_ver.get_binary_location("opera")
1134
+ if os.path.exists(bin_loc):
1135
+ browser_changes += 1
1136
+ browser_set = "opera"
1137
+ sb_config._browser_shortcut = "opera"
1138
+ sb_config._cdp_browser = "opera"
1139
+ sb_config._cdp_bin_loc = bin_loc
1140
+ browser_list.append("--browser=opera")
1141
+ if "--browser=brave" in sys_argv or "--browser brave" in sys_argv:
1142
+ if not bin_loc_in_options:
1143
+ bin_loc = detect_b_ver.get_binary_location("brave")
1144
+ if os.path.exists(bin_loc):
1145
+ browser_changes += 1
1146
+ browser_set = "brave"
1147
+ sb_config._browser_shortcut = "brave"
1148
+ sb_config._cdp_browser = "brave"
1149
+ sb_config._cdp_bin_loc = bin_loc
1150
+ browser_list.append("--browser=brave")
1151
+ if "--browser=comet" in sys_argv or "--browser comet" in sys_argv:
1152
+ if not bin_loc_in_options:
1153
+ bin_loc = detect_b_ver.get_binary_location("comet")
1154
+ if os.path.exists(bin_loc):
1155
+ browser_changes += 1
1156
+ browser_set = "comet"
1157
+ sb_config._browser_shortcut = "comet"
1158
+ sb_config._cdp_browser = "comet"
1159
+ sb_config._cdp_bin_loc = bin_loc
1160
+ browser_list.append("--browser=comet")
1161
+ if "--browser=atlas" in sys_argv or "--browser atlas" in sys_argv:
1162
+ if not bin_loc_in_options:
1163
+ bin_loc = detect_b_ver.get_binary_location("atlas")
1164
+ if os.path.exists(bin_loc):
1165
+ browser_changes += 1
1166
+ browser_set = "atlas"
1167
+ sb_config._browser_shortcut = "atlas"
1168
+ sb_config._cdp_browser = "atlas"
1169
+ sb_config._cdp_bin_loc = bin_loc
1170
+ browser_list.append("--browser=atlas")
1084
1171
  browser_text = browser_set
1085
1172
  if "--chrome" in sys_argv and not browser_set == "chrome":
1086
1173
  browser_changes += 1
@@ -1107,6 +1194,46 @@ class SeleniumBrowser(Plugin):
1107
1194
  browser_text = "safari"
1108
1195
  sb_config._browser_shortcut = "safari"
1109
1196
  browser_list.append("--safari")
1197
+ if "--opera" in sys_argv and not browser_set == "opera":
1198
+ if not bin_loc_in_options:
1199
+ bin_loc = detect_b_ver.get_binary_location("opera")
1200
+ if os.path.exists(bin_loc):
1201
+ browser_changes += 1
1202
+ browser_text = "opera"
1203
+ sb_config._browser_shortcut = "opera"
1204
+ sb_config._cdp_browser = "opera"
1205
+ sb_config._cdp_bin_loc = bin_loc
1206
+ browser_list.append("--opera")
1207
+ if "--brave" in sys_argv and not browser_set == "brave":
1208
+ if not bin_loc_in_options:
1209
+ bin_loc = detect_b_ver.get_binary_location("brave")
1210
+ if os.path.exists(bin_loc):
1211
+ browser_changes += 1
1212
+ browser_text = "brave"
1213
+ sb_config._browser_shortcut = "brave"
1214
+ sb_config._cdp_browser = "brave"
1215
+ sb_config._cdp_bin_loc = bin_loc
1216
+ browser_list.append("--brave")
1217
+ if "--comet" in sys_argv and not browser_set == "comet":
1218
+ if not bin_loc_in_options:
1219
+ bin_loc = detect_b_ver.get_binary_location("comet")
1220
+ if os.path.exists(bin_loc):
1221
+ browser_changes += 1
1222
+ browser_text = "comet"
1223
+ sb_config._browser_shortcut = "comet"
1224
+ sb_config._cdp_browser = "comet"
1225
+ sb_config._cdp_bin_loc = bin_loc
1226
+ browser_list.append("--comet")
1227
+ if "--atlas" in sys_argv and not browser_set == "atlas":
1228
+ if not bin_loc_in_options:
1229
+ bin_loc = detect_b_ver.get_binary_location("atlas")
1230
+ if os.path.exists(bin_loc):
1231
+ browser_changes += 1
1232
+ browser_text = "atlas"
1233
+ sb_config._browser_shortcut = "atlas"
1234
+ sb_config._cdp_browser = "atlas"
1235
+ sb_config._cdp_bin_loc = bin_loc
1236
+ browser_list.append("--atlas")
1110
1237
  if browser_changes > 1:
1111
1238
  message = "\n\n TOO MANY browser types were entered!"
1112
1239
  message += "\n There were %s found:\n > %s" % (
@@ -1118,9 +1245,11 @@ class SeleniumBrowser(Plugin):
1118
1245
  raise Exception(message)
1119
1246
  if browser_text:
1120
1247
  browser = browser_text
1121
- if self.options.recorder_mode and browser not in ["chrome", "edge"]:
1248
+ if self.options.recorder_mode and browser not in [
1249
+ "chrome", "edge", "opera", "brave", "comet", "atlas", "chromium"
1250
+ ]:
1122
1251
  message = (
1123
- "\n\n Recorder Mode ONLY supports Chrome and Edge!"
1252
+ "\n\n Recorder Mode ONLY supports Chromium browsers!"
1124
1253
  '\n (Your browser choice was: "%s")\n' % browser
1125
1254
  )
1126
1255
  raise Exception(message)
@@ -1219,7 +1348,11 @@ class SeleniumBrowser(Plugin):
1219
1348
  test.test.extension_dir = self.options.extension_dir
1220
1349
  test.test.disable_features = self.options.disable_features
1221
1350
  test.test.binary_location = self.options.binary_location
1222
- if self.options.use_cft and not test.test.binary_location:
1351
+ if getattr(sb_config, "_cdp_bin_loc", None):
1352
+ test.test.binary_location = sb_config._cdp_bin_loc
1353
+ if self.options.use_chromium and not test.test.binary_location:
1354
+ test.test.binary_location = "_chromium_"
1355
+ elif self.options.use_cft and not test.test.binary_location:
1223
1356
  test.test.binary_location = "cft"
1224
1357
  elif self.options.use_chs and not test.test.binary_location:
1225
1358
  test.test.binary_location = "chs"
@@ -1232,6 +1365,10 @@ class SeleniumBrowser(Plugin):
1232
1365
  test.test.headless = True
1233
1366
  test.test.headless1 = False
1234
1367
  test.test.headless2 = False
1368
+ if test.test.browser in constants.ChromiumSubs.chromium_subs:
1369
+ if not sb_config.binary_location:
1370
+ test.test.browser = "chrome" # Still uses chromedriver
1371
+ sb_config._browser_shortcut = test.test.browser
1235
1372
  test.test.driver_version = self.options.driver_version
1236
1373
  test.test.page_load_strategy = self.options.page_load_strategy
1237
1374
  test.test.chromium_arg = self.options.chromium_arg
@@ -1390,10 +1527,7 @@ class SeleniumBrowser(Plugin):
1390
1527
 
1391
1528
  def finalize(self, result):
1392
1529
  """This runs after all tests have completed with nosetests."""
1393
- if (
1394
- (hasattr(sb_config, "multi_proxy") and not sb_config.multi_proxy)
1395
- or not hasattr(sb_config, "multi_proxy")
1396
- ):
1530
+ if not getattr(sb_config, "multi_proxy", None):
1397
1531
  proxy_helper.remove_proxy_zip_if_present()
1398
1532
 
1399
1533
  def afterTest(self, test):
@@ -1411,8 +1545,7 @@ class SeleniumBrowser(Plugin):
1411
1545
  pass
1412
1546
  with suppress(Exception):
1413
1547
  if (
1414
- hasattr(self, "_xvfb_display")
1415
- and self._xvfb_display
1548
+ getattr(self, "_xvfb_display", None)
1416
1549
  and hasattr(self._xvfb_display, "stop")
1417
1550
  ):
1418
1551
  self.headless_active = False
@@ -1420,8 +1553,7 @@ class SeleniumBrowser(Plugin):
1420
1553
  self._xvfb_display.stop()
1421
1554
  self._xvfb_display = None
1422
1555
  if (
1423
- hasattr(sb_config, "_virtual_display")
1424
- and sb_config._virtual_display
1556
+ getattr(sb_config, "_virtual_display", None)
1425
1557
  and hasattr(sb_config._virtual_display, "stop")
1426
1558
  ):
1427
1559
  sb_config._virtual_display.stop()
@@ -27,7 +27,6 @@ Output:
27
27
  (Example: Translating "test_1.py" into Japanese with
28
28
  "-c" will create a new file called "test_1_ja.py".)
29
29
  """
30
- import codecs
31
30
  import colorama
32
31
  import os
33
32
  import re
@@ -485,7 +484,7 @@ def main():
485
484
  print("")
486
485
  raise Exception(message)
487
486
 
488
- with open(seleniumbase_file, "r", encoding="utf-8") as f:
487
+ with open(seleniumbase_file, mode="r", encoding="utf-8") as f:
489
488
  all_code = f.read()
490
489
  if "def test_" not in all_code and "from seleniumbase" not in all_code:
491
490
  print("")
@@ -1043,7 +1042,7 @@ def main():
1043
1042
  pass # Print-only run already done
1044
1043
 
1045
1044
  if new_file_name:
1046
- out_file = codecs.open(new_file_name, "w+", encoding="utf-8")
1045
+ out_file = open(new_file_name, mode="w+", encoding="utf-8")
1047
1046
  out_file.writelines("\r\n".join(seleniumbase_lines))
1048
1047
  out_file.close()
1049
1048
  results_saved = (
@@ -5,6 +5,7 @@ import requests
5
5
  import subprocess
6
6
  import sys
7
7
  import time
8
+ from filelock import FileLock
8
9
  import selenium.webdriver.chrome.service
9
10
  import selenium.webdriver.chrome.webdriver
10
11
  import selenium.webdriver.common.service
@@ -117,6 +118,7 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
117
118
  self.patcher = None
118
119
  import fasteners
119
120
  from seleniumbase.fixtures import constants
121
+ from seleniumbase.fixtures import shared_utils
120
122
  if patch_driver:
121
123
  uc_lock = fasteners.InterProcessLock(
122
124
  constants.MultiBrowser.DRIVER_FIXING_LOCK
@@ -161,7 +163,7 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
161
163
  from seleniumbase import config as sb_config
162
164
  if (
163
165
  (("-n" in sys.argv) or (" -n=" in arg_join) or ("-c" in sys.argv))
164
- or (hasattr(sb_config, "multi_proxy") and sb_config.multi_proxy)
166
+ or getattr(sb_config, "multi_proxy", None)
165
167
  or not special_port_free
166
168
  ):
167
169
  debug_port = selenium.webdriver.common.service.utils.free_port()
@@ -195,9 +197,7 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
195
197
  except IndexError:
196
198
  pass
197
199
  if not user_data_dir:
198
- if hasattr(options, "user_data_dir") and getattr(
199
- options, "user_data_dir", None
200
- ):
200
+ if getattr(options, "user_data_dir", None):
201
201
  options.add_argument(
202
202
  "--user-data-dir=%s" % options.user_data_dir
203
203
  )
@@ -284,10 +284,11 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
284
284
  options.binary_location, *options.arguments
285
285
  )
286
286
  else:
287
- gui_lock = fasteners.InterProcessLock(
288
- constants.MultiBrowser.PYAUTOGUILOCK
289
- )
287
+ gui_lock = FileLock(constants.MultiBrowser.PYAUTOGUILOCK)
290
288
  with gui_lock:
289
+ shared_utils.make_writable(
290
+ constants.MultiBrowser.PYAUTOGUILOCK
291
+ )
291
292
  browser = subprocess.Popen(
292
293
  [options.binary_location, *options.arguments],
293
294
  stdin=subprocess.PIPE,
@@ -402,9 +403,7 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
402
403
 
403
404
  def add_cdp_listener(self, event_name, callback):
404
405
  if (
405
- hasattr(self, "reactor")
406
- and self.reactor
407
- and self.reactor is not None
406
+ getattr(self, "reactor", None)
408
407
  and isinstance(self.reactor, Reactor)
409
408
  ):
410
409
  self.reactor.add_event_handler(event_name, callback)
@@ -413,8 +412,7 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
413
412
 
414
413
  def clear_cdp_listeners(self):
415
414
  if (
416
- hasattr(self, "reactor")
417
- and self.reactor
415
+ getattr(self, "reactor", None)
418
416
  and isinstance(self.reactor, Reactor)
419
417
  ):
420
418
  self.reactor.handlers.clear()
@@ -523,7 +521,13 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
523
521
  with suppress(Exception):
524
522
  for window_handle in self.window_handles:
525
523
  self.switch_to.window(window_handle)
526
- if self.current_url.startswith("chrome-extension://"):
524
+ current_url = None
525
+ if hasattr(self, "cdp") and hasattr(self.cdp, "driver"):
526
+ with suppress(Exception):
527
+ current_url = self.cdp.get_current_url()
528
+ if not current_url:
529
+ current_url = self.current_url
530
+ if current_url.startswith("chrome-extension://"):
527
531
  # https://issues.chromium.org/issues/396611138
528
532
  # (Remove the Linux conditional when resolved)
529
533
  # (So that close() is always called)
@@ -1,9 +1,7 @@
1
- import fasteners
2
1
  import json
3
2
  import logging
4
3
  import requests
5
- from seleniumbase.fixtures import constants
6
- from seleniumbase.fixtures import shared_utils
4
+ import websockets
7
5
 
8
6
  log = logging.getLogger(__name__)
9
7
 
@@ -107,15 +105,6 @@ class CDP:
107
105
  return resp.json()
108
106
 
109
107
  async def send(self, method, params):
110
- pip_find_lock = fasteners.InterProcessLock(
111
- constants.PipInstall.FINDLOCK
112
- )
113
- with pip_find_lock:
114
- try:
115
- import websockets
116
- except Exception:
117
- shared_utils.pip_install("websockets")
118
- import websockets
119
108
  self._reqid += 1
120
109
  async with websockets.connect(self.wsurl) as ws:
121
110
  await ws.send(