MarketSquare / webdrivermanager

Python module to facilitate downloading and deploying WebDriver binaries for Chrome, Firefox, Opera & Edge
https://pypi.org/project/webdrivermanager/
MIT License
100 stars 38 forks source link

[FIX]: Fix for unable to get the webdriver through the mac device due to adding m1 build in v0.29.1 #69

Closed jiacwjcw closed 3 years ago

jiacwjcw commented 3 years ago

[FIX]: Fix for unable to get the webdriver through the mac device due to adding m1 build in v0.29.1

Hello, I've found the issue during downloading geckodriver via mac in v0.29.1, it'll always print this log:

raise_runtime_error(f"Error, unable to determine correct filename for {self.bitness}bit {self.os_name}")


After execute pytest of test_gecko.py, the following logs are the same as above log I said:

ERROR: test_download (test.acceptance.test_gecko.GeckoDriverManagerTestsWithAutomaticLocations)

Traceback (most recent call last): File "/Users/jiacw/Documents/Amazon/webdrivermanager/test/acceptance/test_gecko.py", line 16, in test_download filename = self.instance.download(show_progress_bar=False) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/base.py", line 228, in download (download_url, filename) = self.get_download_url(version) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/gecko.py", line 55, in get_download_url url = self._parse_github_api_response(version, response) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/base.py", line 185, in _parse_github_api_response raise_runtime_error(f"Error, unable to determine correct filename for {self.bitness}bit {self.os_name}") File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/misc.py", line 22, in raise_runtime_error raise RuntimeError(msg) RuntimeError: Error, unable to determine correct filename for 64bit mac

ERROR: test_download_and_install (test.acceptance.test_gecko.GeckoDriverManagerTestsWithAutomaticLocations)

Traceback (most recent call last): File "/Users/jiacw/Documents/Amazon/webdrivermanager/test/acceptance/test_gecko.py", line 22, in test_download_and_install driver_link_target, driver_binary = self.instance.download_and_install(show_progress_bar=False) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/base.py", line 291, in download_and_install filename_with_path = self.download(version, show_progress_bar=show_progress_bar, force=force) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/base.py", line 228, in download (download_url, filename) = self.get_download_url(version) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/gecko.py", line 55, in get_download_url url = self._parse_github_api_response(version, response) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/base.py", line 185, in _parse_github_api_response raise_runtime_error(f"Error, unable to determine correct filename for {self.bitness}bit {self.os_name}") File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/misc.py", line 22, in raise_runtime_error raise RuntimeError(msg) RuntimeError: Error, unable to determine correct filename for 64bit mac

ERROR: test_download (test.acceptance.test_gecko.GeckoDriverManagerTestsWithExplicitLocations)

Traceback (most recent call last): File "/Users/jiacw/Documents/Amazon/webdrivermanager/test/acceptance/test_gecko.py", line 33, in test_download filename = self.instance.download(show_progress_bar=False) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/base.py", line 228, in download (download_url, filename) = self.get_download_url(version) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/gecko.py", line 55, in get_download_url url = self._parse_github_api_response(version, response) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/base.py", line 185, in _parse_github_api_response raise_runtime_error(f"Error, unable to determine correct filename for {self.bitness}bit {self.os_name}") File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/misc.py", line 22, in raise_runtime_error raise RuntimeError(msg) RuntimeError: Error, unable to determine correct filename for 64bit mac

ERROR: test_download_and_install (test.acceptance.test_gecko.GeckoDriverManagerTestsWithExplicitLocations)

Traceback (most recent call last): File "/Users/jiacw/Documents/Amazon/webdrivermanager/test/acceptance/test_gecko.py", line 40, in test_download_and_install driver_link_target, driver_binary = self.instance.download_and_install(show_progress_bar=False) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/base.py", line 291, in download_and_install filename_with_path = self.download(version, show_progress_bar=show_progress_bar, force=force) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/base.py", line 228, in download (download_url, filename) = self.get_download_url(version) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/gecko.py", line 55, in get_download_url url = self._parse_github_api_response(version, response) File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/base.py", line 185, in _parse_github_api_response raise_runtime_error(f"Error, unable to determine correct filename for {self.bitness}bit {self.os_name}") File "/Users/jiacw/Documents/Amazon/webdrivermanager/src/webdrivermanager/misc.py", line 22, in raise_runtime_error raise RuntimeError(msg) RuntimeError: Error, unable to determine correct filename for 64bit mac

Ran 4 tests in 3.756s

FAILED (errors=4)


Because there are no any handling to get the correct version between "m1" and "intel" version for Mac device.

As above discussed, I added some functions in base.py to identify what the CPU type is on your device so that it could success to get the correct file which would be downloaded to your device.

def get_mac_cpu_type(self): ... 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]

Testing

python -m unittest test/acceptance/test_gecko.py

Ran 4 tests in 9.137s

rasjani commented 3 years ago

looks good, ill check it a bit in detail later and merge .. thanks for this!

jiacwjcw commented 3 years ago

Sounds great, thanks for helping to review.

rasjani commented 3 years ago

Code, just for gecko is fine but i need to still verify something.

Essentially, the place where this is fixed is in base class of downloader - same piece of code is also used for opera chromium drivers and if it has its own convention to separate arm & intel macs (for which there is no support yet), this patch can cause issues..

Ill still peek over this the weekend and probably merge as is and deal with opera later.

jiacwjcw commented 3 years ago

Hi @rasjani,

Currently, I think it's okay to get the opera chromium because of there is just only one source of opera chromium so that it couldn't be executed in to if len(filename) > 1: ... in line 188 of base.py.


Unit Test of Test Opera

I add some "print" logs to show filenames and filename, It passed to get the opera for macOS now.

python -m unittest test/acceptance/test_opera.py

OperaChromiumDriverManagerTestsWithAutomaticLocations

OperaChromiumDriverManagerTestsWithExplicitLocations


Ran 4 tests in 10.263s

OK