Remove selenium dependency when not using selenium tests
Closes-Bug: 1377372 Change-Id: I6a493989d7280eaa2a1c999a9d1be4365aa77d52
This commit is contained in:
parent
1df385009a
commit
aad4565d9f
|
@ -17,14 +17,24 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
# NOTE: Several distribution can't ship selenium due to its
|
||||
# non-free license. So they have to patch it out of test-requirements.txt
|
||||
# Avoid import failure and force not running selenium tests.
|
||||
# The entire file is encapsulated in the try block because the classes
|
||||
# inherit from the firefox class contained in selenium.webdriver, and
|
||||
# python will throw a NameError if the import is skipped.
|
||||
from selenium.common import exceptions as selenium_exceptions
|
||||
from selenium.webdriver import firefox
|
||||
|
||||
|
||||
class FirefoxBinary(firefox.firefox_binary.FirefoxBinary):
|
||||
"""Workarounds selenium firefox issues.
|
||||
|
||||
|
@ -61,18 +71,25 @@ class FirefoxBinary(firefox.firefox_binary.FirefoxBinary):
|
|||
command, stdout=self._log_file, stderr=subprocess.STDOUT,
|
||||
env=self._firefox_env)
|
||||
|
||||
|
||||
class WebDriver(firefox.webdriver.WebDriver):
|
||||
"""Workarounds selenium firefox issues."""
|
||||
|
||||
def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30,
|
||||
capabilities=None, proxy=None):
|
||||
def __init__(self, firefox_profile=None, firefox_binary=None,
|
||||
timeout=30, capabilities=None, proxy=None):
|
||||
try:
|
||||
super(WebDriver, self).__init__(
|
||||
firefox_profile, FirefoxBinary(), timeout, capabilities, proxy)
|
||||
firefox_profile, FirefoxBinary(), timeout, capabilities,
|
||||
proxy)
|
||||
except selenium_exceptions.WebDriverException:
|
||||
# If we can't start, cleanup profile
|
||||
shutil.rmtree(self.profile.path)
|
||||
if self.profile.tempfolder is not None:
|
||||
shutil.rmtree(self.profile.tempfolder)
|
||||
raise
|
||||
|
||||
except ImportError as e:
|
||||
# NOTE(saschpe): Several distribution can't ship selenium due to its
|
||||
# non-free license. So they have to patch it out of test-requirements.txt
|
||||
# Avoid import failure and force not running selenium tests.
|
||||
LOG.warning("{0}, force WITH_SELENIUM=False".format(str(e)))
|
||||
os.environ['WITH_SELENIUM'] = ''
|
||||
|
|
Loading…
Reference in New Issue