seleniumbase 4.33.5__py3-none-any.whl → 4.33.7__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- seleniumbase/__version__.py +1 -1
- seleniumbase/core/browser_launcher.py +104 -52
- seleniumbase/core/log_helper.py +18 -10
- seleniumbase/core/proxy_helper.py +35 -30
- seleniumbase/core/sb_cdp.py +86 -22
- seleniumbase/core/style_sheet.py +10 -0
- seleniumbase/fixtures/base_case.py +61 -44
- seleniumbase/fixtures/js_utils.py +2 -0
- seleniumbase/fixtures/shared_utils.py +25 -0
- seleniumbase/plugins/pytest_plugin.py +47 -2
- seleniumbase/undetected/cdp_driver/element.py +4 -2
- {seleniumbase-4.33.5.dist-info → seleniumbase-4.33.7.dist-info}/METADATA +2 -2
- {seleniumbase-4.33.5.dist-info → seleniumbase-4.33.7.dist-info}/RECORD +17 -17
- {seleniumbase-4.33.5.dist-info → seleniumbase-4.33.7.dist-info}/LICENSE +0 -0
- {seleniumbase-4.33.5.dist-info → seleniumbase-4.33.7.dist-info}/WHEEL +0 -0
- {seleniumbase-4.33.5.dist-info → seleniumbase-4.33.7.dist-info}/entry_points.txt +0 -0
- {seleniumbase-4.33.5.dist-info → seleniumbase-4.33.7.dist-info}/top_level.txt +0 -0
seleniumbase/__version__.py
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
# seleniumbase package
|
2
|
-
__version__ = "4.33.
|
2
|
+
__version__ = "4.33.7"
|
@@ -97,26 +97,12 @@ def log_d(message):
|
|
97
97
|
print(message)
|
98
98
|
|
99
99
|
|
100
|
-
def make_writable(file_path):
|
101
|
-
# Set permissions to: "If you can read it, you can write it."
|
102
|
-
mode = os.stat(file_path).st_mode
|
103
|
-
mode |= (mode & 0o444) >> 1 # copy R bits to W
|
104
|
-
os.chmod(file_path, mode)
|
105
|
-
|
106
|
-
|
107
|
-
def make_executable(file_path):
|
108
|
-
# Set permissions to: "If you can read it, you can execute it."
|
109
|
-
mode = os.stat(file_path).st_mode
|
110
|
-
mode |= (mode & 0o444) >> 2 # copy R bits to X
|
111
|
-
os.chmod(file_path, mode)
|
112
|
-
|
113
|
-
|
114
100
|
def make_driver_executable_if_not(driver_path):
|
115
101
|
# Verify driver has executable permissions. If not, add them.
|
116
102
|
permissions = oct(os.stat(driver_path)[0])[-3:]
|
117
103
|
if "4" in permissions or "6" in permissions:
|
118
104
|
# We want at least a '5' or '7' to make sure it's executable
|
119
|
-
make_executable(driver_path)
|
105
|
+
shared_utils.make_executable(driver_path)
|
120
106
|
|
121
107
|
|
122
108
|
def extend_driver(driver):
|
@@ -566,6 +552,10 @@ def uc_open_with_cdp_mode(driver, url=None):
|
|
566
552
|
for tab in driver.cdp_base.tabs[-1::-1]:
|
567
553
|
if "chrome-extension://" not in str(tab):
|
568
554
|
with gui_lock:
|
555
|
+
with suppress(Exception):
|
556
|
+
shared_utils.make_writable(
|
557
|
+
constants.MultiBrowser.PYAUTOGUILOCK
|
558
|
+
)
|
569
559
|
loop.run_until_complete(tab.activate())
|
570
560
|
break
|
571
561
|
|
@@ -580,11 +570,17 @@ def uc_open_with_cdp_mode(driver, url=None):
|
|
580
570
|
if page_tab:
|
581
571
|
loop.run_until_complete(page_tab.aopen())
|
582
572
|
with gui_lock:
|
573
|
+
with suppress(Exception):
|
574
|
+
shared_utils.make_writable(
|
575
|
+
constants.MultiBrowser.PYAUTOGUILOCK
|
576
|
+
)
|
583
577
|
loop.run_until_complete(page_tab.activate())
|
584
578
|
|
585
579
|
loop.run_until_complete(driver.cdp_base.update_targets())
|
586
580
|
page = loop.run_until_complete(driver.cdp_base.get(url))
|
587
581
|
with gui_lock:
|
582
|
+
with suppress(Exception):
|
583
|
+
shared_utils.make_writable(constants.MultiBrowser.PYAUTOGUILOCK)
|
588
584
|
loop.run_until_complete(page.activate())
|
589
585
|
loop.run_until_complete(page.wait())
|
590
586
|
if not safe_url:
|
@@ -883,17 +879,12 @@ def install_pyautogui_if_missing(driver):
|
|
883
879
|
with pip_find_lock:
|
884
880
|
pass
|
885
881
|
except Exception:
|
886
|
-
#
|
887
|
-
|
888
|
-
|
889
|
-
try:
|
890
|
-
with pip_find_lock:
|
891
|
-
pass
|
892
|
-
except Exception:
|
893
|
-
# Since missing permissions, skip the locks
|
894
|
-
__install_pyautogui_if_missing()
|
895
|
-
return
|
882
|
+
# Since missing permissions, skip the locks
|
883
|
+
__install_pyautogui_if_missing()
|
884
|
+
return
|
896
885
|
with pip_find_lock: # Prevent issues with multiple processes
|
886
|
+
with suppress(Exception):
|
887
|
+
shared_utils.make_writable(constants.PipInstall.FINDLOCK)
|
897
888
|
__install_pyautogui_if_missing()
|
898
889
|
|
899
890
|
|
@@ -1422,7 +1413,7 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
|
|
1422
1413
|
ctype = "cf_t"
|
1423
1414
|
else:
|
1424
1415
|
return
|
1425
|
-
if not driver.is_connected():
|
1416
|
+
if not driver.is_connected() and not __is_cdp_swap_needed(driver):
|
1426
1417
|
driver.connect()
|
1427
1418
|
time.sleep(2)
|
1428
1419
|
install_pyautogui_if_missing(driver)
|
@@ -1434,7 +1425,10 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
|
|
1434
1425
|
)
|
1435
1426
|
with gui_lock: # Prevent issues with multiple processes
|
1436
1427
|
needs_switch = False
|
1437
|
-
|
1428
|
+
if not __is_cdp_swap_needed(driver):
|
1429
|
+
is_in_frame = js_utils.is_in_frame(driver)
|
1430
|
+
else:
|
1431
|
+
is_in_frame = False
|
1438
1432
|
selector = "#challenge-stage"
|
1439
1433
|
if ctype == "g_rc":
|
1440
1434
|
selector = "#recaptcha-token"
|
@@ -1442,7 +1436,7 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
|
|
1442
1436
|
driver.switch_to.parent_frame()
|
1443
1437
|
needs_switch = True
|
1444
1438
|
is_in_frame = js_utils.is_in_frame(driver)
|
1445
|
-
if not is_in_frame:
|
1439
|
+
if not is_in_frame and not __is_cdp_swap_needed(driver):
|
1446
1440
|
# Make sure the window is on top
|
1447
1441
|
page_actions.switch_to_window(
|
1448
1442
|
driver, driver.current_window_handle, 2, uc_lock=False
|
@@ -1509,17 +1503,18 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
|
|
1509
1503
|
and frame == "iframe"
|
1510
1504
|
):
|
1511
1505
|
frame = 'iframe[title="reCAPTCHA"]'
|
1512
|
-
if not
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
if
|
1520
|
-
driver.
|
1521
|
-
|
1522
|
-
|
1506
|
+
if not __is_cdp_swap_needed(driver):
|
1507
|
+
if not is_in_frame or needs_switch:
|
1508
|
+
# Currently not in frame (or nested frame outside CF one)
|
1509
|
+
try:
|
1510
|
+
if visible_iframe or ctype == "g_rc":
|
1511
|
+
driver.switch_to_frame(frame)
|
1512
|
+
except Exception:
|
1513
|
+
if visible_iframe or ctype == "g_rc":
|
1514
|
+
if driver.is_element_present("iframe"):
|
1515
|
+
driver.switch_to_frame("iframe")
|
1516
|
+
else:
|
1517
|
+
return
|
1523
1518
|
try:
|
1524
1519
|
selector = "div.cf-turnstile"
|
1525
1520
|
if ctype == "g_rc":
|
@@ -1535,11 +1530,11 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
|
|
1535
1530
|
tab_count += 1
|
1536
1531
|
time.sleep(0.027)
|
1537
1532
|
active_element_css = js_utils.get_active_element_css(driver)
|
1538
|
-
print(active_element_css)
|
1539
1533
|
if (
|
1540
1534
|
active_element_css.startswith(selector)
|
1541
1535
|
or active_element_css.endswith(" > div" * 2)
|
1542
1536
|
or (special_form and active_element_css.endswith(" div"))
|
1537
|
+
or (ctype == "g_rc" and "frame[name" in active_element_css)
|
1543
1538
|
):
|
1544
1539
|
found_checkbox = True
|
1545
1540
|
sb_config._saved_cf_tab_count = tab_count
|
@@ -1559,6 +1554,7 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
|
|
1559
1554
|
)
|
1560
1555
|
and hasattr(sb_config, "_saved_cf_tab_count")
|
1561
1556
|
and sb_config._saved_cf_tab_count
|
1557
|
+
and not __is_cdp_swap_needed(driver)
|
1562
1558
|
):
|
1563
1559
|
driver.uc_open_with_disconnect(driver.current_url, 3.8)
|
1564
1560
|
with suppress(Exception):
|
@@ -1773,22 +1769,34 @@ def _add_chrome_proxy_extension(
|
|
1773
1769
|
):
|
1774
1770
|
# Single-threaded
|
1775
1771
|
if zip_it:
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1772
|
+
proxy_zip_lock = fasteners.InterProcessLock(PROXY_ZIP_LOCK)
|
1773
|
+
with proxy_zip_lock:
|
1774
|
+
proxy_helper.create_proxy_ext(
|
1775
|
+
proxy_string, proxy_user, proxy_pass, bypass_list
|
1776
|
+
)
|
1777
|
+
proxy_zip = proxy_helper.PROXY_ZIP_PATH
|
1778
|
+
chrome_options.add_extension(proxy_zip)
|
1781
1779
|
else:
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1780
|
+
proxy_dir_lock = fasteners.InterProcessLock(PROXY_DIR_LOCK)
|
1781
|
+
with proxy_dir_lock:
|
1782
|
+
proxy_helper.create_proxy_ext(
|
1783
|
+
proxy_string,
|
1784
|
+
proxy_user,
|
1785
|
+
proxy_pass,
|
1786
|
+
bypass_list,
|
1787
|
+
zip_it=False,
|
1788
|
+
)
|
1789
|
+
proxy_dir_path = proxy_helper.PROXY_DIR_PATH
|
1790
|
+
chrome_options = add_chrome_ext_dir(
|
1791
|
+
chrome_options, proxy_dir_path
|
1792
|
+
)
|
1787
1793
|
else:
|
1788
1794
|
# Multi-threaded
|
1789
1795
|
if zip_it:
|
1790
1796
|
proxy_zip_lock = fasteners.InterProcessLock(PROXY_ZIP_LOCK)
|
1791
1797
|
with proxy_zip_lock:
|
1798
|
+
with suppress(Exception):
|
1799
|
+
shared_utils.make_writable(PROXY_ZIP_LOCK)
|
1792
1800
|
if multi_proxy:
|
1793
1801
|
_set_proxy_filenames()
|
1794
1802
|
if not os.path.exists(proxy_helper.PROXY_ZIP_PATH):
|
@@ -1800,6 +1808,8 @@ def _add_chrome_proxy_extension(
|
|
1800
1808
|
else:
|
1801
1809
|
proxy_dir_lock = fasteners.InterProcessLock(PROXY_DIR_LOCK)
|
1802
1810
|
with proxy_dir_lock:
|
1811
|
+
with suppress(Exception):
|
1812
|
+
shared_utils.make_writable(PROXY_DIR_LOCK)
|
1803
1813
|
if multi_proxy:
|
1804
1814
|
_set_proxy_filenames()
|
1805
1815
|
if not os.path.exists(proxy_helper.PROXY_DIR_PATH):
|
@@ -1808,7 +1818,7 @@ def _add_chrome_proxy_extension(
|
|
1808
1818
|
proxy_user,
|
1809
1819
|
proxy_pass,
|
1810
1820
|
bypass_list,
|
1811
|
-
False,
|
1821
|
+
zip_it=False,
|
1812
1822
|
)
|
1813
1823
|
chrome_options = add_chrome_ext_dir(
|
1814
1824
|
chrome_options, proxy_helper.PROXY_DIR_PATH
|
@@ -1825,6 +1835,8 @@ def is_using_uc(undetectable, browser_name):
|
|
1825
1835
|
def _unzip_to_new_folder(zip_file, folder):
|
1826
1836
|
proxy_dir_lock = fasteners.InterProcessLock(PROXY_DIR_LOCK)
|
1827
1837
|
with proxy_dir_lock:
|
1838
|
+
with suppress(Exception):
|
1839
|
+
shared_utils.make_writable(PROXY_DIR_LOCK)
|
1828
1840
|
if not os.path.exists(folder):
|
1829
1841
|
import zipfile
|
1830
1842
|
zip_ref = zipfile.ZipFile(zip_file, "r")
|
@@ -2934,6 +2946,8 @@ def get_remote_driver(
|
|
2934
2946
|
constants.PipInstall.FINDLOCK
|
2935
2947
|
)
|
2936
2948
|
with pip_find_lock: # Prevent issues with multiple processes
|
2949
|
+
with suppress(Exception):
|
2950
|
+
shared_utils.make_writable(constants.PipInstall.FINDLOCK)
|
2937
2951
|
try:
|
2938
2952
|
from seleniumwire import webdriver
|
2939
2953
|
import blinker
|
@@ -3371,6 +3385,8 @@ def get_local_driver(
|
|
3371
3385
|
constants.PipInstall.FINDLOCK
|
3372
3386
|
)
|
3373
3387
|
with pip_find_lock: # Prevent issues with multiple processes
|
3388
|
+
with suppress(Exception):
|
3389
|
+
shared_utils.make_writable(constants.PipInstall.FINDLOCK)
|
3374
3390
|
try:
|
3375
3391
|
from seleniumwire import webdriver
|
3376
3392
|
import blinker
|
@@ -3434,6 +3450,10 @@ def get_local_driver(
|
|
3434
3450
|
constants.MultiBrowser.DRIVER_FIXING_LOCK
|
3435
3451
|
)
|
3436
3452
|
with geckodriver_fixing_lock:
|
3453
|
+
with suppress(Exception):
|
3454
|
+
shared_utils.make_writable(
|
3455
|
+
constants.MultiBrowser.DRIVER_FIXING_LOCK
|
3456
|
+
)
|
3437
3457
|
if not geckodriver_on_path():
|
3438
3458
|
sys_args = sys.argv # Save a copy of sys args
|
3439
3459
|
log_d(
|
@@ -3736,6 +3756,10 @@ def get_local_driver(
|
|
3736
3756
|
constants.MultiBrowser.DRIVER_FIXING_LOCK
|
3737
3757
|
)
|
3738
3758
|
with edgedriver_fixing_lock:
|
3759
|
+
with suppress(Exception):
|
3760
|
+
shared_utils.make_writable(
|
3761
|
+
constants.MultiBrowser.DRIVER_FIXING_LOCK
|
3762
|
+
)
|
3739
3763
|
msg = "Microsoft Edge Driver not found."
|
3740
3764
|
if edgedriver_upgrade_needed:
|
3741
3765
|
msg = "Microsoft Edge Driver update needed."
|
@@ -4119,6 +4143,10 @@ def get_local_driver(
|
|
4119
4143
|
constants.MultiBrowser.DRIVER_FIXING_LOCK
|
4120
4144
|
)
|
4121
4145
|
with edgedriver_fixing_lock:
|
4146
|
+
with suppress(Exception):
|
4147
|
+
shared_utils.make_writable(
|
4148
|
+
constants.MultiBrowser.DRIVER_FIXING_LOCK
|
4149
|
+
)
|
4122
4150
|
with suppress(Exception):
|
4123
4151
|
if not _was_driver_repaired():
|
4124
4152
|
_repair_edgedriver(edge_version)
|
@@ -4501,6 +4529,10 @@ def get_local_driver(
|
|
4501
4529
|
constants.MultiBrowser.DRIVER_FIXING_LOCK
|
4502
4530
|
)
|
4503
4531
|
with chromedriver_fixing_lock:
|
4532
|
+
with suppress(Exception):
|
4533
|
+
shared_utils.make_writable(
|
4534
|
+
constants.MultiBrowser.DRIVER_FIXING_LOCK
|
4535
|
+
)
|
4504
4536
|
msg = "chromedriver update needed. Getting it now:"
|
4505
4537
|
if not path_chromedriver:
|
4506
4538
|
msg = "chromedriver not found. Getting it now:"
|
@@ -4592,6 +4624,10 @@ def get_local_driver(
|
|
4592
4624
|
constants.MultiBrowser.DRIVER_FIXING_LOCK
|
4593
4625
|
)
|
4594
4626
|
with uc_lock: # Avoid multithreaded issues
|
4627
|
+
with suppress(Exception):
|
4628
|
+
shared_utils.make_writable(
|
4629
|
+
constants.MultiBrowser.DRIVER_FIXING_LOCK
|
4630
|
+
)
|
4595
4631
|
if make_uc_driver_from_chromedriver:
|
4596
4632
|
if os.path.exists(LOCAL_CHROMEDRIVER):
|
4597
4633
|
with suppress(Exception):
|
@@ -4824,7 +4860,12 @@ def get_local_driver(
|
|
4824
4860
|
)
|
4825
4861
|
uc_activated = True
|
4826
4862
|
except URLError as e:
|
4827
|
-
if
|
4863
|
+
if (
|
4864
|
+
IS_MAC
|
4865
|
+
and hasattr(e, "args")
|
4866
|
+
and isinstance(e.args, (list, tuple))
|
4867
|
+
and cert in e.args[0]
|
4868
|
+
):
|
4828
4869
|
mac_certificate_error = True
|
4829
4870
|
else:
|
4830
4871
|
raise
|
@@ -4851,6 +4892,10 @@ def get_local_driver(
|
|
4851
4892
|
if not os.path.exists(cf_lock_path):
|
4852
4893
|
# Avoid multithreaded issues
|
4853
4894
|
with cf_lock:
|
4895
|
+
with suppress(Exception):
|
4896
|
+
shared_utils.make_writable(
|
4897
|
+
cf_lock_path
|
4898
|
+
)
|
4854
4899
|
# Install Python Certificates (MAC)
|
4855
4900
|
os.system(
|
4856
4901
|
r"bash /Applications/Python*/"
|
@@ -4994,6 +5039,10 @@ def get_local_driver(
|
|
4994
5039
|
constants.MultiBrowser.DRIVER_FIXING_LOCK
|
4995
5040
|
)
|
4996
5041
|
with chromedriver_fixing_lock:
|
5042
|
+
with suppress(Exception):
|
5043
|
+
shared_utils.make_writable(
|
5044
|
+
constants.MultiBrowser.DRIVER_FIXING_LOCK
|
5045
|
+
)
|
4997
5046
|
if not _was_driver_repaired():
|
4998
5047
|
_repair_chromedriver(
|
4999
5048
|
chrome_options, headless_options, mcv
|
@@ -5192,7 +5241,10 @@ def get_local_driver(
|
|
5192
5241
|
chromedr_fixing_lock = fasteners.InterProcessLock(
|
5193
5242
|
constants.MultiBrowser.DRIVER_FIXING_LOCK
|
5194
5243
|
)
|
5244
|
+
D_F_L = constants.MultiBrowser.DRIVER_FIXING_LOCK
|
5195
5245
|
with chromedr_fixing_lock:
|
5246
|
+
with suppress(Exception):
|
5247
|
+
shared_utils.make_writable(D_F_L)
|
5196
5248
|
if not _was_driver_repaired():
|
5197
5249
|
with suppress(Exception):
|
5198
5250
|
_repair_chromedriver(
|
seleniumbase/core/log_helper.py
CHANGED
@@ -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):
|
@@ -33,6 +34,8 @@ def log_screenshot(test_logpath, driver, screenshot=None, get=False):
|
|
33
34
|
if screenshot != screenshot_warning:
|
34
35
|
with open(screenshot_path, "wb") as file:
|
35
36
|
file.write(screenshot)
|
37
|
+
with suppress(Exception):
|
38
|
+
shared_utils.make_writable(screenshot_path)
|
36
39
|
else:
|
37
40
|
print("WARNING: %s" % screenshot_warning)
|
38
41
|
if get:
|
@@ -282,13 +285,14 @@ def log_test_failure_data(test, test_logpath, driver, browser, url=None):
|
|
282
285
|
sb_config._report_time = the_time
|
283
286
|
sb_config._report_traceback = traceback_message
|
284
287
|
sb_config._report_exception = exc_message
|
285
|
-
|
286
|
-
|
288
|
+
if not os.path.exists(test_logpath):
|
289
|
+
with suppress(Exception):
|
287
290
|
os.makedirs(test_logpath)
|
288
291
|
with suppress(Exception):
|
289
292
|
log_file = codecs.open(basic_file_path, "w+", encoding="utf-8")
|
290
293
|
log_file.writelines("\r\n".join(data_to_save))
|
291
294
|
log_file.close()
|
295
|
+
shared_utils.make_writable(basic_file_path)
|
292
296
|
|
293
297
|
|
294
298
|
def log_skipped_test_data(test, test_logpath, driver, browser, reason):
|
@@ -339,9 +343,11 @@ def log_skipped_test_data(test, test_logpath, driver, browser, reason):
|
|
339
343
|
data_to_save.append(" * Skip Reason: %s" % reason)
|
340
344
|
data_to_save.append("")
|
341
345
|
file_path = os.path.join(test_logpath, "skip_reason.txt")
|
342
|
-
|
343
|
-
|
344
|
-
|
346
|
+
with suppress(Exception):
|
347
|
+
log_file = codecs.open(file_path, "w+", encoding="utf-8")
|
348
|
+
log_file.writelines("\r\n".join(data_to_save))
|
349
|
+
log_file.close()
|
350
|
+
shared_utils.make_writable(file_path)
|
345
351
|
|
346
352
|
|
347
353
|
def log_page_source(test_logpath, driver, source=None):
|
@@ -364,13 +370,15 @@ def log_page_source(test_logpath, driver, source=None):
|
|
364
370
|
"unresponsive, or closed prematurely!</h4>"
|
365
371
|
)
|
366
372
|
)
|
367
|
-
|
368
|
-
|
373
|
+
if not os.path.exists(test_logpath):
|
374
|
+
with suppress(Exception):
|
369
375
|
os.makedirs(test_logpath)
|
370
376
|
html_file_path = os.path.join(test_logpath, html_file_name)
|
371
|
-
|
372
|
-
|
373
|
-
|
377
|
+
with suppress(Exception):
|
378
|
+
html_file = codecs.open(html_file_path, "w+", encoding="utf-8")
|
379
|
+
html_file.write(page_source)
|
380
|
+
html_file.close()
|
381
|
+
shared_utils.make_writable(html_file_path)
|
374
382
|
|
375
383
|
|
376
384
|
def get_test_id(test):
|
@@ -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
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
proxy_ext_dir
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
145
|
-
|
150
|
+
if os.path.exists(PROXY_ZIP_PATH):
|
151
|
+
with suppress(Exception):
|
146
152
|
os.remove(PROXY_ZIP_PATH)
|
147
|
-
|
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):
|