seleniumbase 4.33.4__py3-none-any.whl → 4.34.2__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. seleniumbase/__version__.py +1 -1
  2. seleniumbase/behave/behave_sb.py +10 -2
  3. seleniumbase/console_scripts/run.py +6 -2
  4. seleniumbase/console_scripts/sb_commander.py +5 -5
  5. seleniumbase/console_scripts/sb_install.py +235 -6
  6. seleniumbase/console_scripts/sb_mkdir.py +1 -0
  7. seleniumbase/core/browser_launcher.py +358 -105
  8. seleniumbase/core/log_helper.py +33 -12
  9. seleniumbase/core/proxy_helper.py +35 -30
  10. seleniumbase/core/sb_cdp.py +277 -74
  11. seleniumbase/core/settings_parser.py +2 -0
  12. seleniumbase/core/style_sheet.py +10 -0
  13. seleniumbase/fixtures/base_case.py +216 -127
  14. seleniumbase/fixtures/constants.py +3 -0
  15. seleniumbase/fixtures/js_utils.py +2 -0
  16. seleniumbase/fixtures/page_actions.py +7 -2
  17. seleniumbase/fixtures/shared_utils.py +25 -0
  18. seleniumbase/plugins/driver_manager.py +28 -0
  19. seleniumbase/plugins/pytest_plugin.py +110 -0
  20. seleniumbase/plugins/sb_manager.py +41 -0
  21. seleniumbase/plugins/selenium_plugin.py +9 -0
  22. seleniumbase/undetected/cdp_driver/_contradict.py +3 -3
  23. seleniumbase/undetected/cdp_driver/browser.py +8 -6
  24. seleniumbase/undetected/cdp_driver/cdp_util.py +3 -0
  25. seleniumbase/undetected/cdp_driver/config.py +0 -1
  26. seleniumbase/undetected/cdp_driver/element.py +22 -20
  27. seleniumbase/undetected/patcher.py +20 -5
  28. {seleniumbase-4.33.4.dist-info → seleniumbase-4.34.2.dist-info}/LICENSE +1 -1
  29. {seleniumbase-4.33.4.dist-info → seleniumbase-4.34.2.dist-info}/METADATA +111 -86
  30. {seleniumbase-4.33.4.dist-info → seleniumbase-4.34.2.dist-info}/RECORD +33 -33
  31. {seleniumbase-4.33.4.dist-info → seleniumbase-4.34.2.dist-info}/WHEEL +1 -1
  32. {seleniumbase-4.33.4.dist-info → seleniumbase-4.34.2.dist-info}/entry_points.txt +0 -0
  33. {seleniumbase-4.33.4.dist-info → seleniumbase-4.34.2.dist-info}/top_level.txt +0 -0
@@ -7,6 +7,7 @@ from contextlib import suppress
7
7
  from seleniumbase import config as sb_config
8
8
  from seleniumbase.config import settings
9
9
  from seleniumbase.fixtures import constants
10
+ from seleniumbase.fixtures import shared_utils
10
11
 
11
12
  python3_11_or_newer = False
12
13
  if sys.version_info >= (3, 11):
@@ -14,6 +15,11 @@ if sys.version_info >= (3, 11):
14
15
  py311_patch2 = constants.PatchPy311.PATCH
15
16
 
16
17
 
18
+ def __is_cdp_swap_needed(driver):
19
+ """If the driver is disconnected, use a CDP method when available."""
20
+ return shared_utils.is_cdp_swap_needed(driver)
21
+
22
+
17
23
  def log_screenshot(test_logpath, driver, screenshot=None, get=False):
18
24
  screenshot_name = settings.SCREENSHOT_NAME
19
25
  screenshot_path = os.path.join(test_logpath, screenshot_name)
@@ -33,6 +39,8 @@ def log_screenshot(test_logpath, driver, screenshot=None, get=False):
33
39
  if screenshot != screenshot_warning:
34
40
  with open(screenshot_path, "wb") as file:
35
41
  file.write(screenshot)
42
+ with suppress(Exception):
43
+ shared_utils.make_writable(screenshot_path)
36
44
  else:
37
45
  print("WARNING: %s" % screenshot_warning)
38
46
  if get:
@@ -282,13 +290,14 @@ def log_test_failure_data(test, test_logpath, driver, browser, url=None):
282
290
  sb_config._report_time = the_time
283
291
  sb_config._report_traceback = traceback_message
284
292
  sb_config._report_exception = exc_message
285
- with suppress(Exception):
286
- if not os.path.exists(test_logpath):
293
+ if not os.path.exists(test_logpath):
294
+ with suppress(Exception):
287
295
  os.makedirs(test_logpath)
288
296
  with suppress(Exception):
289
297
  log_file = codecs.open(basic_file_path, "w+", encoding="utf-8")
290
298
  log_file.writelines("\r\n".join(data_to_save))
291
299
  log_file.close()
300
+ shared_utils.make_writable(basic_file_path)
292
301
 
293
302
 
294
303
  def log_skipped_test_data(test, test_logpath, driver, browser, reason):
@@ -339,9 +348,11 @@ def log_skipped_test_data(test, test_logpath, driver, browser, reason):
339
348
  data_to_save.append(" * Skip Reason: %s" % reason)
340
349
  data_to_save.append("")
341
350
  file_path = os.path.join(test_logpath, "skip_reason.txt")
342
- log_file = codecs.open(file_path, "w+", encoding="utf-8")
343
- log_file.writelines("\r\n".join(data_to_save))
344
- log_file.close()
351
+ with suppress(Exception):
352
+ log_file = codecs.open(file_path, "w+", encoding="utf-8")
353
+ log_file.writelines("\r\n".join(data_to_save))
354
+ log_file.close()
355
+ shared_utils.make_writable(file_path)
345
356
 
346
357
 
347
358
  def log_page_source(test_logpath, driver, source=None):
@@ -350,7 +361,11 @@ def log_page_source(test_logpath, driver, source=None):
350
361
  page_source = source
351
362
  else:
352
363
  try:
353
- page_source = driver.page_source
364
+ page_source = None
365
+ if __is_cdp_swap_needed(driver):
366
+ page_source = driver.cdp.get_page_source()
367
+ else:
368
+ page_source = driver.page_source
354
369
  page_source = get_html_source_with_base_href(driver, page_source)
355
370
  except Exception:
356
371
  source = constants.Warnings.PAGE_SOURCE_UNDEFINED
@@ -364,13 +379,15 @@ def log_page_source(test_logpath, driver, source=None):
364
379
  "unresponsive, or closed prematurely!</h4>"
365
380
  )
366
381
  )
367
- with suppress(Exception):
368
- if not os.path.exists(test_logpath):
382
+ if not os.path.exists(test_logpath):
383
+ with suppress(Exception):
369
384
  os.makedirs(test_logpath)
370
385
  html_file_path = os.path.join(test_logpath, html_file_name)
371
- html_file = codecs.open(html_file_path, "w+", encoding="utf-8")
372
- html_file.write(page_source)
373
- html_file.close()
386
+ with suppress(Exception):
387
+ html_file = codecs.open(html_file_path, "w+", encoding="utf-8")
388
+ html_file.write(page_source)
389
+ html_file.close()
390
+ shared_utils.make_writable(html_file_path)
374
391
 
375
392
 
376
393
  def get_test_id(test):
@@ -440,7 +457,11 @@ def get_test_name(test):
440
457
 
441
458
  def get_last_page(driver):
442
459
  try:
443
- last_page = driver.current_url
460
+ last_page = None
461
+ if __is_cdp_swap_needed(driver):
462
+ last_page = driver.cdp.get_current_url()
463
+ else:
464
+ last_page = driver.current_url
444
465
  except Exception:
445
466
  last_page = "[WARNING! Browser Not Open!]"
446
467
  if len(last_page) < 5:
@@ -2,10 +2,12 @@ import os
2
2
  import re
3
3
  import warnings
4
4
  import zipfile
5
+ from contextlib import suppress
5
6
  from seleniumbase.config import proxy_list
6
7
  from seleniumbase.config import settings
7
8
  from seleniumbase.fixtures import constants
8
9
  from seleniumbase.fixtures import page_utils
10
+ from seleniumbase.fixtures import shared_utils
9
11
 
10
12
  DOWNLOADS_DIR = constants.Files.DOWNLOADS_FOLDER
11
13
  PROXY_ZIP_PATH = os.path.join(DOWNLOADS_DIR, "proxy.zip")
@@ -109,31 +111,35 @@ def create_proxy_ext(
109
111
  """"minimum_chrome_version":"22.0.0"\n"""
110
112
  """}"""
111
113
  )
112
- import threading
113
-
114
- lock = threading.RLock() # Support multi-threaded tests. Eg. "pytest -n=4"
115
- with lock:
116
- abs_path = os.path.abspath(".")
117
- downloads_path = os.path.join(abs_path, DOWNLOADS_DIR)
118
- if not os.path.exists(downloads_path):
119
- os.mkdir(downloads_path)
120
- if zip_it:
121
- zf = zipfile.ZipFile(PROXY_ZIP_PATH, mode="w")
122
- zf.writestr("background.js", background_js)
123
- zf.writestr("manifest.json", manifest_json)
124
- zf.close()
125
- else:
126
- proxy_ext_dir = PROXY_DIR_PATH
127
- if not os.path.exists(proxy_ext_dir):
128
- os.mkdir(proxy_ext_dir)
129
- manifest_file = os.path.join(proxy_ext_dir, "manifest.json")
130
- with open(manifest_file, mode="w") as f:
131
- f.write(manifest_json)
132
- proxy_host = proxy_string.split(":")[0]
133
- proxy_port = proxy_string.split(":")[1]
134
- background_file = os.path.join(proxy_ext_dir, "background.js")
135
- with open(background_file, mode="w") as f:
136
- f.write(background_js)
114
+ abs_path = os.path.abspath(".")
115
+ downloads_path = os.path.join(abs_path, DOWNLOADS_DIR)
116
+ if not os.path.exists(downloads_path):
117
+ os.mkdir(downloads_path)
118
+ if zip_it:
119
+ zf = zipfile.ZipFile(PROXY_ZIP_PATH, mode="w")
120
+ zf.writestr("background.js", background_js)
121
+ zf.writestr("manifest.json", manifest_json)
122
+ zf.close()
123
+ with suppress(Exception):
124
+ shared_utils.make_writable(PROXY_ZIP_PATH)
125
+ else:
126
+ proxy_ext_dir = PROXY_DIR_PATH
127
+ if not os.path.exists(proxy_ext_dir):
128
+ os.mkdir(proxy_ext_dir)
129
+ with suppress(Exception):
130
+ shared_utils.make_writable(proxy_ext_dir)
131
+ manifest_file = os.path.join(proxy_ext_dir, "manifest.json")
132
+ with open(manifest_file, mode="w") as f:
133
+ f.write(manifest_json)
134
+ with suppress(Exception):
135
+ shared_utils.make_writable(manifest_json)
136
+ proxy_host = proxy_string.split(":")[0]
137
+ proxy_port = proxy_string.split(":")[1]
138
+ background_file = os.path.join(proxy_ext_dir, "background.js")
139
+ with open(background_file, mode="w") as f:
140
+ f.write(background_js)
141
+ with suppress(Exception):
142
+ shared_utils.make_writable(background_js)
137
143
 
138
144
 
139
145
  def remove_proxy_zip_if_present():
@@ -141,13 +147,12 @@ def remove_proxy_zip_if_present():
141
147
  Used in the implementation of https://stackoverflow.com/a/35293284
142
148
  for https://stackoverflow.com/questions/12848327/
143
149
  """
144
- try:
145
- if os.path.exists(PROXY_ZIP_PATH):
150
+ if os.path.exists(PROXY_ZIP_PATH):
151
+ with suppress(Exception):
146
152
  os.remove(PROXY_ZIP_PATH)
147
- if os.path.exists(PROXY_ZIP_LOCK):
153
+ if os.path.exists(PROXY_ZIP_LOCK):
154
+ with suppress(Exception):
148
155
  os.remove(PROXY_ZIP_LOCK)
149
- except Exception:
150
- pass
151
156
 
152
157
 
153
158
  def validate_proxy_string(proxy_string):