|
1 | 1 | import os
|
| 2 | +import random |
2 | 3 | import re
|
3 | 4 | import sys
|
4 | 5 | import threading
|
|
15 | 16 | from seleniumbase import drivers # webdriver storage folder for SeleniumBase
|
16 | 17 | DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
|
17 | 18 | PROXY_ZIP_PATH = proxy_helper.PROXY_ZIP_PATH
|
| 19 | +PROXY_ZIP_PATH_2 = proxy_helper.PROXY_ZIP_PATH_2 |
18 | 20 | PLATFORM = sys.platform
|
19 | 21 | IS_WINDOWS = False
|
20 | 22 | LOCAL_CHROMEDRIVER = None
|
@@ -57,22 +59,24 @@ def _add_chrome_proxy_extension(
|
57 | 59 | chrome_options, proxy_string, proxy_user, proxy_pass):
|
58 | 60 | """ Implementation of https://stackoverflow.com/a/35293284 for
|
59 | 61 | https://stackoverflow.com/questions/12848327/
|
60 |
| - (Run Selenium on a proxy server that requires authentication.) |
61 |
| - The retry_on_exception is only needed for multithreaded runs |
62 |
| - because proxy.zip is a common file shared between all tests |
63 |
| - in a single run. """ |
| 62 | + (Run Selenium on a proxy server that requires authentication.) """ |
64 | 63 | if not "".join(sys.argv) == "-c":
|
65 | 64 | # Single-threaded
|
66 | 65 | proxy_helper.create_proxy_zip(proxy_string, proxy_user, proxy_pass)
|
67 | 66 | else:
|
68 | 67 | # Pytest multi-threaded test
|
69 | 68 | lock = threading.Lock()
|
70 | 69 | with lock:
|
| 70 | + time.sleep(random.uniform(0.02, 0.15)) |
71 | 71 | if not os.path.exists(PROXY_ZIP_PATH):
|
72 | 72 | proxy_helper.create_proxy_zip(
|
73 | 73 | proxy_string, proxy_user, proxy_pass)
|
74 |
| - time.sleep(0.3) |
75 |
| - chrome_options.add_extension(PROXY_ZIP_PATH) |
| 74 | + time.sleep(random.uniform(0.1, 0.2)) |
| 75 | + proxy_zip = PROXY_ZIP_PATH |
| 76 | + if not os.path.exists(PROXY_ZIP_PATH): |
| 77 | + # Handle "Permission denied" on the default proxy.zip path |
| 78 | + proxy_zip = PROXY_ZIP_PATH_2 |
| 79 | + chrome_options.add_extension(proxy_zip) |
76 | 80 | return chrome_options
|
77 | 81 |
|
78 | 82 |
|
@@ -102,7 +106,6 @@ def _set_chrome_options(
|
102 | 106 | if proxy_auth:
|
103 | 107 | chrome_options = _add_chrome_proxy_extension(
|
104 | 108 | chrome_options, proxy_string, proxy_user, proxy_pass)
|
105 |
| - chrome_options.add_extension(DRIVER_DIR + "/proxy.zip") |
106 | 109 | chrome_options.add_argument('--proxy-server=%s' % proxy_string)
|
107 | 110 | return chrome_options
|
108 | 111 |
|
@@ -209,9 +212,6 @@ def get_driver(browser_name, headless=False, use_grid=False,
|
209 | 212 | "either Chrome or Firefox may be used.)")
|
210 | 213 | proxy_string = validate_proxy_string(proxy_string)
|
211 | 214 | if proxy_string and proxy_user and proxy_pass:
|
212 |
| - if not os.path.exists(PROXY_ZIP_PATH): |
213 |
| - proxy_helper.create_proxy_zip( |
214 |
| - proxy_string, proxy_user, proxy_pass) |
215 | 215 | proxy_auth = True
|
216 | 216 | if use_grid:
|
217 | 217 | return get_remote_driver(
|
|
0 commit comments