Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge fix #89

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/webdrivermanager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, download_root=None, link_path=None, os_name=None, bitness=Non
self.bitness = bitness

self.os_name = os_name or self.get_os_name()
self.dirs = AppDirs("WebDriverManager", "rasjani")
self.dirs = AppDirs("WebDriverManager", os.getlogin())
base_path = self._get_basepath()
self.download_root = Path(download_root or base_path)

Expand Down Expand Up @@ -141,7 +141,7 @@ def get_driver_filename(self):

def get_mac_cpu_type(self):
# Identify mac CPU type, refer to https://stackoverflow.com/questions/65970469/what-does-platform-system-and-platform-architecture-return-on-apple-m1-silic
return "m1" if platform.processor() is "arm" else "intel" if self.os_name == "mac" else ""
return "m1" if platform.processor() == "arm" else "intel" if self.os_name == "mac" else ""

def _parse_version(self, version):
method = version.strip().lower()
Expand Down Expand Up @@ -186,8 +186,8 @@ def _parse_github_api_response(self, version, response):
raise_runtime_error(f"Error, unable to find a download for os: {self.os_name}")

if len(filename) > 1:
if self.os_name is "mac":
filename = [name for name in filenames if "aarch64" in name] if mac_cpu_type is "arm" else [name for name in filenames if "aarch64" not in name]
if self.os_name == "mac":
filename = [name for name in filenames if "aarch64" in name] if mac_cpu_type == "arm" else [name for name in filenames if "aarch64" not in name]
else:
filename = [name for name in filenames if self.os_name + self.bitness in name and not name.endswith(".asc")]
if len(filename) != 1:
Expand Down
81 changes: 44 additions & 37 deletions src/webdrivermanager/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class EdgeDriverManager(WebDriverManagerBase):

driver_filenames = {
"win": ["MicrosoftWebDriver.exe", "msedgedriver.exe"],
"mac": None,
"linux": None,
"mac": "msedgedriver",
"linux": "msedgedriver",
}

edge_driver_base_url = "https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/"
Expand All @@ -30,53 +30,60 @@ def get_download_url(self, version="latest"):
:param version: String representing the version of the web driver binary to download. For example, "2.39".
Default if no version is specified is "latest". The version string should match the version
as specified on the download page of the webdriver binary.
:returns: The download URL for the Google Chrome driver binary.
:returns: The download URL for the MSEdge driver binary.
"""
version = self._parse_version(version)
LOGGER.debug("Detected OS: %sbit %s", self.bitness, self.os_name)

# TODO: handle error 500 by sleep & retry here
resp = requests.get(self.edge_driver_base_url)
if resp.status_code != 200:
raise_runtime_error(f"Error, unable to get version number for latest release, got code: {resp.status_code}")

url = self._get_download_url(resp, version)
return (url, os.path.split(urlparse(url).path)[1])
url = self._get_download_url(version)
return url, os.path.split(urlparse(url).path)[1]

def get_latest_version(self):
# TODO: handle error 500 by sleep & retry here
resp = requests.get(self.edge_driver_base_url)
if resp.status_code != 200:
raise_runtime_error(f"Error, unable to get version number for latest release, got code: {resp.status_code}")

return self._get_version_number(resp)
return "latest"

def get_compatible_version(self):
raise NotImplementedError

def _get_download_url(self, body, version):
def _get_download_url(self, version):
try:
tree = BeautifulSoup(body.text, "html.parser")
mstr = f"Release {version}"
link_texts = tree.find_all("a", string=re.compile(mstr))
if "index.html" in link_texts[0]["href"]:
local_bitness = self.bitness
if local_bitness == "32":
local_bitness = "86"
mstr = f"WebDriver for release number {version} x{local_bitness}"
link_texts = tree.find_all("a", {"aria-label": re.compile(mstr)})
return link_texts[0]["href"]
except Exception:
return None
latest_stable_download_urls = {
"mac": "https://msedgedriver.azureedge.net/98.0.1108.62/edgedriver_mac64.zip",
"win": {"32": "https://msedgedriver.azureedge.net/98.0.1108.62/edgedriver_win32.zip",
"86": "https://msedgedriver.azureedge.net/98.0.1108.62/edgedriver_win64.zip",
"ARM64": "https://msedgedriver.azureedge.net/98.0.1108.62/edgedriver_arm64.zip"},
"linux": "https://msedgedriver.azureedge.net/98.0.1108.62/edgedriver_linux64.zip"
}
os_name = self.os_name

def _get_version_number(self, body):
try:
tree = BeautifulSoup(body.text, "html.parser")
link_texts = tree.find_all("a", string=re.compile("Release "))
results = re.findall(r"\"WebDriver for release number ([\d\.]+)\"", str(link_texts[0]))
if bool(results and results[0]):
return results[0]
if version == "latest":
if os_name in ["mac", "linux"]:
return latest_stable_download_urls[os_name]

return None
# TODO: Add support for Windows ARM
if os_name == "win" and self.bitness == "32":
return latest_stable_download_urls["win"]["32"]

return latest_stable_download_urls["win"]["86"]

driver_files = {
"mac": "edgedriver_mac64.zip",
"win": {"32": "edgedriver_win32.zip",
"86": "edgedriver_win64.zip",
"ARM64": "edgedriver_arm64.zip"},
"linux": "edgedriver_linux64.zip"
}
driver_file = ''
if os_name == "mac":
driver_file = driver_files["mac"]
elif os_name == "linux":
driver_file = driver_files["linux"]
elif os_name == "win":
# TODO: Add support for Windows ARM
if self.bitness == "32":
driver_file = driver_files["win"]["32"]
else:
driver_file = driver_files["win"]["86"]

return f"https://msedgedriver.azureedge.net/{version}/{driver_file}"
except Exception:
return None
8 changes: 4 additions & 4 deletions test/acceptance/test_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class EdgeDriverManagerTestsWithAutomaticLocations(AutomaticBaseTest):

@flaky
def test_download(self):
self.instance = self.DRIVER_MANAGER(os_name="win")
self.instance = self.DRIVER_MANAGER()
filename = self.instance.download(show_progress_bar=False)
self.assertTrue(filename.is_file(), NO_FILE)

@flaky
def test_download_and_install(self):
self.instance = self.DRIVER_MANAGER(os_name="win")
self.instance = self.DRIVER_MANAGER()
driver_link_target, driver_binary = self.instance.download_and_install(show_progress_bar=False)
self.assertTrue(driver_binary.is_file(), NO_FILE)
self.assertTrue(driver_link_target.is_file(), NO_LINK_FILE)
Expand All @@ -29,14 +29,14 @@ class EdgeDriverManagerTestsWithExplicitLocations(ExplicitBaseTest):

@flaky
def test_download(self):
self.instance = self.DRIVER_MANAGER(download_root=self.temp_dir.name, os_name="win")
self.instance = self.DRIVER_MANAGER(download_root=self.temp_dir.name)
filename = self.instance.download(show_progress_bar=False)
self.assertTrue(filename.is_file(), NO_FILE)

@flaky
def test_download_and_install(self):
link_path = self.make_link_dir()
self.instance = self.DRIVER_MANAGER(download_root=self.temp_dir.name, link_path=link_path, os_name="win")
self.instance = self.DRIVER_MANAGER(download_root=self.temp_dir.name, link_path=link_path)
driver_link_target, driver_binary = self.instance.download_and_install(show_progress_bar=False)
self.assertTrue(driver_binary.is_file(), NO_FILE)
self.assertTrue(driver_link_target.is_file(), NO_LINK_FILE)