Skip to content

Commit 7af84e6

Browse files
committed
Refactoring
1 parent 00bdb4a commit 7af84e6

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import time
1010
import urllib3
1111
import warnings
12-
from importlib.util import find_spec
1312
from selenium import webdriver
1413
from selenium.webdriver.chrome.service import Service as ChromeService
1514
from selenium.webdriver.edge.service import Service as EdgeService
@@ -1239,12 +1238,14 @@ def get_remote_driver(
12391238
pip_find_lock = fasteners.InterProcessLock(
12401239
constants.PipInstall.FINDLOCK
12411240
)
1242-
with pip_find_lock: # Prevent multi-processes mode issues
1243-
if not find_spec("selenium-wire"):
1241+
with pip_find_lock:
1242+
try:
1243+
from seleniumwire import webdriver
1244+
except Exception:
12441245
shared_utils.pip_install(
12451246
"selenium-wire", version=constants.SeleniumWire.VER
12461247
)
1247-
from seleniumwire import webdriver
1248+
from seleniumwire import webdriver
12481249
else:
12491250
from selenium import webdriver
12501251

seleniumbase/core/mysql.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ def __init__(self, database_env="test", conf_creds=None):
99
import fasteners
1010
import sys
1111
import time
12-
from importlib.util import find_spec
1312
from seleniumbase import config as sb_config
1413
from seleniumbase.config import settings
1514
from seleniumbase.core import settings_parser
@@ -19,14 +18,15 @@ def __init__(self, database_env="test", conf_creds=None):
1918
pip_find_lock = fasteners.InterProcessLock(
2019
constants.PipInstall.FINDLOCK
2120
)
22-
with pip_find_lock: # Prevent multi-processes mode issues
23-
if not find_spec("pymysql"):
21+
with pip_find_lock:
22+
try:
23+
import pymysql
24+
except Exception:
2425
if sys.version_info >= (3, 6):
2526
shared_utils.pip_install("pymysql", version="1.0.2")
2627
else:
2728
shared_utils.pip_install("pymysql", version="0.10.1")
28-
import pymysql
29-
29+
import pymysql
3030
db_server = settings.DB_HOST
3131
db_port = settings.DB_PORT
3232
db_user = settings.DB_USERNAME

seleniumbase/core/s3_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ def __init__(
1616
selenium_secret_key=settings.S3_SELENIUM_SECRET_KEY,
1717
):
1818
import fasteners
19-
from importlib.util import find_spec
2019
from seleniumbase.fixtures import constants
2120
from seleniumbase.fixtures import shared_utils
2221

2322
pip_find_lock = fasteners.InterProcessLock(
2423
constants.PipInstall.FINDLOCK
2524
)
26-
with pip_find_lock: # Prevent multi-processes mode issues
27-
if not find_spec("boto"):
25+
with pip_find_lock:
26+
try:
27+
from boto.s3.connection import S3Connection
28+
except Exception:
2829
shared_utils.pip_install("boto", version="2.49.0")
29-
from boto.s3.connection import S3Connection
30-
30+
from boto.s3.connection import S3Connection
3131
self.conn = S3Connection(selenium_access_key, selenium_secret_key)
3232
self.bucket = self.conn.get_bucket(log_bucket)
3333
self.bucket_url = bucket_url

seleniumbase/fixtures/base_case.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def test_anything(self):
4545
import unittest
4646
import urllib3
4747
from contextlib import contextmanager
48-
from importlib.util import find_spec
4948
from selenium.common.exceptions import (
5049
ElementClickInterceptedException as ECI_Exception,
5150
ElementNotInteractableException as ENI_Exception,
@@ -2914,7 +2913,7 @@ def switch_to_frame(self, frame, timeout=None):
29142913
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
29152914
timeout = self.__get_new_timeout(timeout)
29162915
if self.__needs_minimum_wait():
2917-
time.sleep(0.03)
2916+
time.sleep(0.035)
29182917
if type(frame) is str and self.is_element_visible(frame):
29192918
try:
29202919
self.scroll_to(frame, timeout=1)
@@ -2945,11 +2944,11 @@ def switch_to_frame(self, frame, timeout=None):
29452944
return
29462945
self.wait_for_ready_state_complete()
29472946
if self.__needs_minimum_wait():
2948-
time.sleep(0.03)
2947+
time.sleep(0.035)
29492948
page_actions.switch_to_frame(self.driver, frame, timeout)
29502949
self.wait_for_ready_state_complete()
29512950
if self.__needs_minimum_wait():
2952-
time.sleep(0.01)
2951+
time.sleep(0.015)
29532952

29542953
def switch_to_default_content(self):
29552954
"""Brings driver control outside the current iframe.
@@ -5903,11 +5902,12 @@ def get_pdf_text(
59035902
pip_find_lock = fasteners.InterProcessLock(
59045903
constants.PipInstall.FINDLOCK
59055904
)
5906-
with pip_find_lock: # Prevent multi-processes mode issues
5907-
if not find_spec("pdfminer.six"):
5905+
with pip_find_lock:
5906+
try:
5907+
from pdfminer.high_level import extract_text
5908+
except Exception:
59085909
shared_utils.pip_install("pdfminer.six")
5909-
from pdfminer.high_level import extract_text
5910-
5910+
from pdfminer.high_level import extract_text
59115911
if not password:
59125912
password = ""
59135913
if not maxpages:

0 commit comments

Comments
 (0)