Skip to content

Commit

Permalink
Refactor os management (#542)
Browse files Browse the repository at this point in the history
* delete driver manager options

---------

Co-authored-by: s.pirohov <[email protected]>
  • Loading branch information
SergeyPirogov and s.pirohov authored Jul 23, 2023
1 parent 068aec7 commit 06997dc
Show file tree
Hide file tree
Showing 26 changed files with 434 additions and 399 deletions.
10 changes: 6 additions & 4 deletions tests/test_brave_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from selenium import webdriver

from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.driver_cache import DriverCacheManager
from webdriver_manager.core.logger import log
from webdriver_manager.core.utils import ChromeType, os_name, OSType
from webdriver_manager.core.os_manager import ChromeType, OSType, OperationSystemManager

This comment has been minimized.

Copy link
@johanneswilm

johanneswilm Jul 31, 2023

@SergeyPirogov In the README.md it still mentions from webdriver_manager.core.utils import ChromeType. I had to go here into the commits to find the new location.



def test_driver_with_ssl_verify_disabled_can_be_downloaded(ssl_verify_enable):
Expand All @@ -16,8 +17,8 @@ def test_driver_with_ssl_verify_disabled_can_be_downloaded(ssl_verify_enable):
"ssl_disabled",
)
driver_path = ChromeDriverManager(
version="87.0.4280.88",
path=custom_path,
driver_version="87.0.4280.88",
cache_manager=DriverCacheManager(custom_path),
chrome_type=ChromeType.BRAVE,
).install()

Expand Down Expand Up @@ -54,6 +55,7 @@ def test_brave_manager_with_wrong_version():

@pytest.mark.parametrize('os_type', ['win32', 'win64'])
def test_can_get_brave_for_win(os_type):
path = ChromeDriverManager(version="83.0.4103.39", os_type=os_type,
path = ChromeDriverManager(driver_version="83.0.4103.39",
os_system_manager=OperationSystemManager(os_type),
chrome_type=ChromeType.BRAVE).install()
assert os.path.exists(path)
15 changes: 9 additions & 6 deletions tests/test_chrome_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from webdriver_manager.core.constants import ROOT_FOLDER_NAME
from selenium.webdriver.chrome.service import Service

os.environ.setdefault("WDM_LOCAL", "true")
from webdriver_manager.core.driver_cache import DriverCacheManager
from webdriver_manager.core.os_manager import OperationSystemManager

os.environ.setdefault("WDM_LOCAL", "false")


def test_chrome_manager_with_cache(delete_drivers_dir):
Expand Down Expand Up @@ -36,7 +39,7 @@ def test_chrome_manager_with_project_root_local_folder(delete_drivers_dir):

def test_driver_can_be_saved_to_custom_path():
custom_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "custom")
path = ChromeDriverManager(version="87.0.4280.88", path=custom_path).install()
path = ChromeDriverManager(driver_version="87.0.4280.88", cache_manager=DriverCacheManager(custom_path)).install()
assert os.path.exists(path)
assert custom_path in path

Expand All @@ -60,14 +63,14 @@ def test_driver_with_ssl_verify_disabled_can_be_downloaded(ssl_verify_enable):
os.path.dirname(__file__)),
"ssl_disabled",
)
driver_path = ChromeDriverManager(path=custom_path).install()
driver_path = ChromeDriverManager(cache_manager=DriverCacheManager(custom_path)).install()
os.environ['WDM_SSL_VERIFY'] = '1'
assert os.path.exists(driver_path)


def test_chrome_manager_cached_driver_with_selenium():
custom_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "custom-cache")
manager = ChromeDriverManager(path=custom_path)
manager = ChromeDriverManager(cache_manager=DriverCacheManager(custom_path))
driver = webdriver.Chrome(service=Service(manager.install()))
driver.get("http://automation-remarks.com")

Expand All @@ -82,10 +85,10 @@ def test_chrome_manager_cached_driver_with_selenium():
with open(metadata_file, 'w') as outfile:
json.dump(data, outfile)

ChromeDriverManager(path=custom_path).install()
ChromeDriverManager(cache_manager=DriverCacheManager(custom_path)).install()


@pytest.mark.parametrize('os_type', ['win32', 'win64', 'mac64', 'mac64_m1'])
def test_can_get_chrome_for_os(os_type):
path = ChromeDriverManager(os_type=os_type).install()
path = ChromeDriverManager(os_system_manager=OperationSystemManager(os_type)).install()
assert os.path.exists(path)
12 changes: 7 additions & 5 deletions tests/test_chromium_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import pytest

from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType
from webdriver_manager.core.driver_cache import DriverCacheManager
from webdriver_manager.core.os_manager import ChromeType, OperationSystemManager


def test_driver_with_ssl_verify_disabled_can_be_downloaded(ssl_verify_enable):
Expand All @@ -13,8 +14,8 @@ def test_driver_with_ssl_verify_disabled_can_be_downloaded(ssl_verify_enable):
"ssl_disabled",
)
driver_path = ChromeDriverManager(
version="87.0.4280.88",
path=custom_path,
driver_version="87.0.4280.88",
cache_manager=DriverCacheManager(custom_path),
chrome_type=ChromeType.CHROMIUM,
).install()

Expand All @@ -29,7 +30,7 @@ def test_chromium_manager_with_specific_version():
def test_driver_can_be_saved_to_custom_path():
custom_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "custom")

path = ChromeDriverManager(version="87.0.4280.88", path=custom_path,
path = ChromeDriverManager(driver_version="87.0.4280.88", cache_manager=DriverCacheManager(custom_path),
chrome_type=ChromeType.CHROMIUM).install()
assert os.path.exists(path)
assert custom_path in path
Expand All @@ -43,6 +44,7 @@ def test_chromium_manager_with_wrong_version():

@pytest.mark.parametrize('os_type', ['win32', 'win64'])
def test_can_get_chromium_for_win(os_type):
path = ChromeDriverManager(version="83.0.4103.39", os_type=os_type,
path = ChromeDriverManager(driver_version="83.0.4103.39",
os_system_manager=OperationSystemManager(os_type),
chrome_type=ChromeType.CHROMIUM).install()
assert os.path.exists(path)
9 changes: 6 additions & 3 deletions tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

from webdriver_manager.core.constants import DEFAULT_PROJECT_ROOT_CACHE_PATH
from webdriver_manager.core.download_manager import WDMDownloadManager
from webdriver_manager.core.file_manager import FileManager
from webdriver_manager.core.http import WDMHttpClient
from webdriver_manager.core.utils import ChromeType, FileManager
from webdriver_manager.core.os_manager import OperationSystemManager, ChromeType
from webdriver_manager.drivers.chrome import ChromeDriver

download_manager = WDMDownloadManager()
file_manager = FileManager()
file_manager = FileManager(OperationSystemManager())


def test_can_download_driver_as_zip_file(delete_drivers_dir):
Expand All @@ -31,7 +32,9 @@ def test_can_download_driver_as_tar_gz(delete_drivers_dir):

@pytest.mark.parametrize('version', ["2.26"])
def test_can_download_chrome_driver(delete_drivers_dir, version):
driver = ChromeDriver(name="chromedriver", version=version, os_type="win32",
driver = ChromeDriver(name="chromedriver",
driver_version=version,
os_system_manager=OperationSystemManager("win32"),
url="http://chromedriver.storage.googleapis.com",
latest_release_url="http://chromedriver.storage.googleapis.com/LATEST_RELEASE",
chrome_type=ChromeType.GOOGLE, http_client=WDMHttpClient())
Expand Down
13 changes: 7 additions & 6 deletions tests/test_edge_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from selenium import webdriver
from selenium.webdriver.edge.service import Service

from webdriver_manager.core.driver_cache import DriverCacheManager
from webdriver_manager.core.os_manager import PATTERN, ChromeType, OperationSystemManager
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from webdriver_manager.core.utils import PATTERN, ChromeType


def test_edge_manager_with_selenium():
Expand All @@ -22,7 +23,7 @@ def test_driver_with_ssl_verify_disabled_can_be_downloaded(ssl_verify_enable):
os.path.dirname(os.path.dirname(__file__)),
"ssl_disabled",
)
driver_path = EdgeChromiumDriverManager(path=custom_path).install()
driver_path = EdgeChromiumDriverManager(cache_manager=DriverCacheManager(custom_path)).install()
os.environ['WDM_SSL_VERIFY'] = '1'
assert os.path.exists(driver_path)

Expand All @@ -31,7 +32,7 @@ def test_edge_manager_with_wrong_version():
with pytest.raises(ValueError) as ex:
EdgeChromiumDriverManager(
version="0.2",
os_type='win64',
os_system_manager=OperationSystemManager("win64")
).install()

assert (
Expand All @@ -45,7 +46,7 @@ def test_edge_manager_with_wrong_version():
def test_edge_with_specific_version(os_type, specific_version):
bin_path = EdgeChromiumDriverManager(
version=specific_version,
os_type=os_type,
os_system_manager=OperationSystemManager(os_type),
).install()
assert os.path.exists(bin_path)

Expand All @@ -55,11 +56,11 @@ def test_edge_with_specific_version(os_type, specific_version):
def test_can_get_edge_driver_from_cache(os_type, specific_version):
EdgeChromiumDriverManager(
version=specific_version,
os_type=os_type,
os_system_manager=OperationSystemManager(os_type),
).install()
driver_path = EdgeChromiumDriverManager(
version=specific_version,
os_type=os_type
os_system_manager=OperationSystemManager(os_type)
).install()
assert os.path.exists(driver_path)

Expand Down
10 changes: 6 additions & 4 deletions tests/test_firefox_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from selenium import webdriver
from selenium.webdriver.firefox.service import Service

from webdriver_manager.core.driver_cache import DriverCacheManager
from webdriver_manager.core.os_manager import OperationSystemManager
from webdriver_manager.firefox import GeckoDriverManager


Expand All @@ -26,7 +28,7 @@ def test_driver_with_ssl_verify_disabled_can_be_downloaded(ssl_verify_enable):
os.path.dirname(os.path.dirname(__file__)),
"ssl_disabled",
)
driver_path = GeckoDriverManager(path=custom_path).install()
driver_path = GeckoDriverManager(cache_manager=DriverCacheManager(custom_path)).install()
os.environ['WDM_SSL_VERIFY'] = '1'
assert os.path.exists(driver_path)

Expand All @@ -46,7 +48,7 @@ def test_gecko_manager_with_correct_version_and_token(delete_drivers_dir):


def test_can_download_ff_x64(delete_drivers_dir):
driver_path = GeckoDriverManager(os_type="win64").install()
driver_path = GeckoDriverManager(os_system_manager=OperationSystemManager("win64")).install()
assert os.path.exists(driver_path)


Expand All @@ -57,6 +59,6 @@ def test_can_download_ff_x64(delete_drivers_dir):
'mac64',
'mac64_m1'])
def test_can_get_driver_from_cache(os_type):
GeckoDriverManager(os_type=os_type).install()
driver_path = GeckoDriverManager(os_type=os_type).install()
GeckoDriverManager(os_system_manager=OperationSystemManager(os_type)).install()
driver_path = GeckoDriverManager(os_system_manager=OperationSystemManager(os_type)).install()
assert os.path.exists(driver_path)
10 changes: 6 additions & 4 deletions tests/test_ie_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pytest

from webdriver_manager.core.driver_cache import DriverCacheManager
from webdriver_manager.core.os_manager import OperationSystemManager
from webdriver_manager.microsoft import IEDriverManager


Expand All @@ -20,21 +22,21 @@ def test_driver_with_ssl_verify_disabled_can_be_downloaded(ssl_verify_enable):
os.path.dirname(os.path.dirname(__file__)),
"ssl_disabled",
)
driver_path = IEDriverManager(path=custom_path).install()
driver_path = IEDriverManager(cache_manager=DriverCacheManager(custom_path)).install()
os.environ['WDM_SSL_VERIFY'] = '1'
assert os.path.exists(driver_path)


@pytest.mark.parametrize('os_type', ['win32', 'win64'])
def test_can_download_ie_driver_x64(os_type):
path = IEDriverManager(os_type=os_type).install()
path = IEDriverManager(os_system_manager=OperationSystemManager(os_type)).install()
assert os.path.exists(path)


@pytest.mark.parametrize('os_type', ['win32', 'win64'])
def test_can_get_ie_driver_from_cache(os_type):
IEDriverManager(os_type=os_type).install()
driver_path = IEDriverManager(os_type=os_type).install()
IEDriverManager(os_system_manager=OperationSystemManager(os_type)).install()
driver_path = IEDriverManager(os_system_manager=OperationSystemManager(os_type)).install()
assert os.path.exists(driver_path)


Expand Down
19 changes: 10 additions & 9 deletions tests/test_opera_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

from webdriver_manager.core.utils import os_type as get_os_type
from webdriver_manager.core.driver_cache import DriverCacheManager
from webdriver_manager.core.os_manager import OperationSystemManager
from webdriver_manager.opera import OperaDriverManager


Expand All @@ -20,7 +21,7 @@ def test_driver_with_ssl_verify_disabled_can_be_downloaded(ssl_verify_enable):
os.path.dirname(os.path.dirname(__file__)),
"ssl_disabled",
)
driver_path = OperaDriverManager(path=custom_path).install()
driver_path = OperaDriverManager(cache_manager=DriverCacheManager(custom_path)).install()
os.environ['WDM_SSL_VERIFY'] = '1'
assert os.path.exists(driver_path)

Expand All @@ -29,8 +30,8 @@ def test_operadriver_manager_with_selenium():
driver_path = OperaDriverManager().install()
options = webdriver.ChromeOptions()
options.add_experimental_option('w3c', True)

if get_os_type() in ["win64", "win32"]:
os_type = OperationSystemManager().get_os_type()
if os_type in ["win64", "win32"]:
paths = [f for f in glob.glob(
f"C:/Users/{os.getlogin()}/AppData/Local/Programs/Opera/**",
recursive=True
Expand All @@ -39,11 +40,11 @@ def test_operadriver_manager_with_selenium():
if os.path.isfile(path) and path.endswith("opera.exe"):
options.binary_location = path
elif (
(get_os_type() in ["linux64", "linux32"])
(os_type in ["linux64", "linux32"])
and not os.path.exists('/usr/bin/opera')
):
options.binary_location = "/usr/bin/opera"
elif get_os_type() in "mac64":
elif os_type in "mac64":
options.binary_location = "/Applications/Opera.app/Contents/MacOS/Opera"
web_service = Service(driver_path)
web_service.start()
Expand All @@ -64,7 +65,7 @@ def test_opera_driver_manager_with_wrong_version():

@pytest.mark.parametrize('path', ['.', None])
def test_opera_driver_manager_with_correct_version_and_token(path):
driver_path = OperaDriverManager(version="v.2.45", path=path).install()
driver_path = OperaDriverManager(version="v.2.45", cache_manager=DriverCacheManager(path)).install()
assert os.path.exists(driver_path)


Expand All @@ -73,6 +74,6 @@ def test_opera_driver_manager_with_correct_version_and_token(path):
'linux64',
'mac64'])
def test_can_get_driver_from_cache(os_type):
OperaDriverManager(os_type=os_type).install()
driver_path = OperaDriverManager(os_type=os_type).install()
OperaDriverManager(os_system_manager=OperationSystemManager(os_type)).install()
driver_path = OperaDriverManager(os_system_manager=OperationSystemManager(os_type)).install()
assert os.path.exists(driver_path)
4 changes: 2 additions & 2 deletions tests_negative/test_browsers_not_installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from selenium.webdriver.firefox.service import Service as FFService

from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.os_manager import OperationSystemManager, ChromeType, OSType
from webdriver_manager.firefox import GeckoDriverManager
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from webdriver_manager.core.utils import OSType, os_name, ChromeType


@pytest.mark.skip(reason="it is not stable on CI")
Expand All @@ -19,7 +19,7 @@ def test_brave_not_installed():
OSType.LINUX: "/usr/bin/brave-browser",
OSType.MAC: "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser",
OSType.WIN: f"{os.getenv('LOCALAPPDATA')}\\BraveSoftware\\Brave-Browser\\Application\\brave.exe",
}[os_name()]
}[OperationSystemManager.get_os_name()]

option = webdriver.ChromeOptions()
option.binary_location = binary_location
Expand Down
Loading

0 comments on commit 06997dc

Please sign in to comment.