|
9 | 9 | from seleniumbase.fixtures import constants
|
10 | 10 |
|
11 | 11 |
|
| 12 | +def _set_chrome_options(downloads_path, proxy_string): |
| 13 | + chrome_options = webdriver.ChromeOptions() |
| 14 | + prefs = { |
| 15 | + "download.default_directory": downloads_path, |
| 16 | + "credentials_enable_service": False, |
| 17 | + "profile": { |
| 18 | + "password_manager_enabled": False |
| 19 | + } |
| 20 | + } |
| 21 | + chrome_options.add_experimental_option("prefs", prefs) |
| 22 | + chrome_options.add_argument("--test-type") |
| 23 | + chrome_options.add_argument("--no-first-run") |
| 24 | + chrome_options.add_argument("--ignore-certificate-errors") |
| 25 | + chrome_options.add_argument("--allow-file-access-from-files") |
| 26 | + chrome_options.add_argument("--allow-insecure-localhost") |
| 27 | + chrome_options.add_argument("--allow-running-insecure-content") |
| 28 | + chrome_options.add_argument("--disable-infobars") |
| 29 | + chrome_options.add_argument("--disable-save-password-bubble") |
| 30 | + chrome_options.add_argument("--disable-single-click-autofill") |
| 31 | + chrome_options.add_argument("--disable-translate") |
| 32 | + chrome_options.add_argument("--disable-web-security") |
| 33 | + if proxy_string: |
| 34 | + chrome_options.add_argument('--proxy-server=%s' % proxy_string) |
| 35 | + if settings.START_CHROME_IN_FULL_SCREEN_MODE: |
| 36 | + # Run Chrome in full screen mode on WINDOWS |
| 37 | + chrome_options.add_argument("--start-maximized") |
| 38 | + # Run Chrome in full screen mode on MAC/Linux |
| 39 | + chrome_options.add_argument("--kiosk") |
| 40 | + return chrome_options |
| 41 | + |
| 42 | + |
12 | 43 | def _create_firefox_profile(downloads_path, proxy_string):
|
13 | 44 | profile = webdriver.FirefoxProfile()
|
14 | 45 | profile.set_preference("reader.parse-on-load.enabled", False)
|
@@ -82,41 +113,14 @@ def get_remote_driver(browser_name, headless, servername, port, proxy_string):
|
82 | 113 | address = "http://%s:%s/wd/hub" % (servername, port)
|
83 | 114 |
|
84 | 115 | if browser_name == constants.Browser.GOOGLE_CHROME:
|
85 |
| - chrome_options = webdriver.ChromeOptions() |
86 |
| - prefs = { |
87 |
| - "download.default_directory": downloads_path, |
88 |
| - "credentials_enable_service": False, |
89 |
| - "profile": { |
90 |
| - "password_manager_enabled": False |
91 |
| - } |
92 |
| - } |
93 |
| - chrome_options.add_experimental_option("prefs", prefs) |
94 |
| - chrome_options.add_argument("--test-type") |
95 |
| - chrome_options.add_argument("--no-first-run") |
96 |
| - chrome_options.add_argument("--ignore-certificate-errors") |
97 |
| - chrome_options.add_argument("--allow-file-access-from-files") |
98 |
| - chrome_options.add_argument("--allow-insecure-localhost") |
99 |
| - chrome_options.add_argument("--allow-running-insecure-content") |
100 |
| - chrome_options.add_argument("--disable-infobars") |
101 |
| - chrome_options.add_argument("--disable-save-password-bubble") |
102 |
| - chrome_options.add_argument("--disable-single-click-autofill") |
103 |
| - chrome_options.add_argument("--disable-translate") |
104 |
| - chrome_options.add_argument("--disable-web-security") |
| 116 | + chrome_options = _set_chrome_options(downloads_path, proxy_string) |
105 | 117 | if headless:
|
106 | 118 | chrome_options.add_argument("--headless")
|
107 |
| - if proxy_string: |
108 |
| - chrome_options.add_argument('--proxy-server=%s' % proxy_string) |
109 |
| - if settings.START_CHROME_IN_FULL_SCREEN_MODE: |
110 |
| - # Run Chrome in full screen mode on WINDOWS |
111 |
| - chrome_options.add_argument("--start-maximized") |
112 |
| - # Run Chrome in full screen mode on MAC/Linux |
113 |
| - chrome_options.add_argument("--kiosk") |
114 | 119 | capabilities = chrome_options.to_capabilities()
|
115 | 120 | return webdriver.Remote(
|
116 | 121 | command_executor=address,
|
117 | 122 | desired_capabilities=capabilities)
|
118 |
| - |
119 |
| - if browser_name == constants.Browser.FIREFOX: |
| 123 | + elif browser_name == constants.Browser.FIREFOX: |
120 | 124 | try:
|
121 | 125 | # Use Geckodriver for Firefox if it's on the PATH
|
122 | 126 | profile = _create_firefox_profile(downloads_path, proxy_string)
|
@@ -144,23 +148,22 @@ def get_remote_driver(browser_name, headless, servername, port, proxy_string):
|
144 | 148 | command_executor=address,
|
145 | 149 | desired_capabilities=capabilities,
|
146 | 150 | browser_profile=profile)
|
147 |
| - |
148 |
| - if browser_name == constants.Browser.INTERNET_EXPLORER: |
| 151 | + elif browser_name == constants.Browser.INTERNET_EXPLORER: |
149 | 152 | return webdriver.Remote(
|
150 | 153 | command_executor=address,
|
151 | 154 | desired_capabilities=(
|
152 | 155 | webdriver.DesiredCapabilities.INTERNETEXPLORER))
|
153 |
| - if browser_name == constants.Browser.EDGE: |
| 156 | + elif browser_name == constants.Browser.EDGE: |
154 | 157 | return webdriver.Remote(
|
155 | 158 | command_executor=address,
|
156 | 159 | desired_capabilities=(
|
157 | 160 | webdriver.DesiredCapabilities.EDGE))
|
158 |
| - if browser_name == constants.Browser.SAFARI: |
| 161 | + elif browser_name == constants.Browser.SAFARI: |
159 | 162 | return webdriver.Remote(
|
160 | 163 | command_executor=address,
|
161 | 164 | desired_capabilities=(
|
162 | 165 | webdriver.DesiredCapabilities.SAFARI))
|
163 |
| - if browser_name == constants.Browser.PHANTOM_JS: |
| 166 | + elif browser_name == constants.Browser.PHANTOM_JS: |
164 | 167 | with warnings.catch_warnings():
|
165 | 168 | # Ignore "PhantomJS has been deprecated" UserWarning
|
166 | 169 | warnings.simplefilter("ignore", category=UserWarning)
|
@@ -203,48 +206,22 @@ def get_local_driver(browser_name, headless, proxy_string):
|
203 | 206 | if headless:
|
204 | 207 | raise Exception(e)
|
205 | 208 | return webdriver.Firefox()
|
206 |
| - if browser_name == constants.Browser.INTERNET_EXPLORER: |
| 209 | + elif browser_name == constants.Browser.INTERNET_EXPLORER: |
207 | 210 | return webdriver.Ie()
|
208 |
| - if browser_name == constants.Browser.EDGE: |
| 211 | + elif browser_name == constants.Browser.EDGE: |
209 | 212 | return webdriver.Edge()
|
210 |
| - if browser_name == constants.Browser.SAFARI: |
| 213 | + elif browser_name == constants.Browser.SAFARI: |
211 | 214 | return webdriver.Safari()
|
212 |
| - if browser_name == constants.Browser.PHANTOM_JS: |
| 215 | + elif browser_name == constants.Browser.PHANTOM_JS: |
213 | 216 | with warnings.catch_warnings():
|
214 | 217 | # Ignore "PhantomJS has been deprecated" UserWarning
|
215 | 218 | warnings.simplefilter("ignore", category=UserWarning)
|
216 | 219 | return webdriver.PhantomJS()
|
217 |
| - if browser_name == constants.Browser.GOOGLE_CHROME: |
| 220 | + elif browser_name == constants.Browser.GOOGLE_CHROME: |
218 | 221 | try:
|
219 |
| - chrome_options = webdriver.ChromeOptions() |
220 |
| - prefs = { |
221 |
| - "download.default_directory": downloads_path, |
222 |
| - "credentials_enable_service": False, |
223 |
| - "profile": { |
224 |
| - "password_manager_enabled": False |
225 |
| - } |
226 |
| - } |
227 |
| - chrome_options.add_experimental_option("prefs", prefs) |
228 |
| - chrome_options.add_argument("--test-type") |
229 |
| - chrome_options.add_argument("--no-first-run") |
230 |
| - chrome_options.add_argument("--ignore-certificate-errors") |
231 |
| - chrome_options.add_argument("--allow-file-access-from-files") |
232 |
| - chrome_options.add_argument("--allow-insecure-localhost") |
233 |
| - chrome_options.add_argument("--allow-running-insecure-content") |
234 |
| - chrome_options.add_argument("--disable-infobars") |
235 |
| - chrome_options.add_argument("--disable-save-password-bubble") |
236 |
| - chrome_options.add_argument("--disable-single-click-autofill") |
237 |
| - chrome_options.add_argument("--disable-translate") |
238 |
| - chrome_options.add_argument("--disable-web-security") |
| 222 | + chrome_options = _set_chrome_options(downloads_path, proxy_string) |
239 | 223 | if headless:
|
240 | 224 | chrome_options.add_argument("--headless")
|
241 |
| - if proxy_string: |
242 |
| - chrome_options.add_argument('--proxy-server=%s' % proxy_string) |
243 |
| - if settings.START_CHROME_IN_FULL_SCREEN_MODE: |
244 |
| - # Run Chrome in full screen mode on WINDOWS |
245 |
| - chrome_options.add_argument("--start-maximized") |
246 |
| - # Run Chrome in full screen mode on MAC/Linux |
247 |
| - chrome_options.add_argument("--kiosk") |
248 | 225 | return webdriver.Chrome(options=chrome_options)
|
249 | 226 | except Exception as e:
|
250 | 227 | if headless:
|
|
0 commit comments