Skip to content

Commit

Permalink
Fix latest chrome (#8)
Browse files Browse the repository at this point in the history
* This should make latest chrome work again

* update version.py

* quotes

* try this

* remove 3.10 for now
  • Loading branch information
Wolfe1 authored Aug 11, 2023
1 parent 0bd80a0 commit f390489
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.7, 3.8, 3.9, 3.10 ]
python-version: [ 3.7, 3.8, 3.9 ]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion webdrivermanager/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

VERSION = '0.7.7'
VERSION = '0.8.0'


def get_version():
Expand Down
54 changes: 29 additions & 25 deletions webdrivermanager/webdrivermanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,17 @@ class ChromeDriverManager(WebDriverManagerBase):
"""Class for downloading the Google Chrome WebDriver.
"""

chrome_driver_base_url = 'https://www.googleapis.com/storage/v1/b/chromedriver'
chrome_driver_base_url = 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json'

def _get_latest_version_number(self):
resp = requests.get(self.chrome_driver_base_url + '/o/LATEST_RELEASE')
resp = requests.get(self.chrome_driver_base_url)
if resp.status_code != 200:
raise_runtime_error('Error, unable to get version number for latest release, got code: {0}'.format(resp.status_code))
raise RuntimeError(
'Error, unable to get version number for latest release, got code: {0}'.format(resp.status_code))

latest_release = requests.get(resp.json()['mediaLink'])
return latest_release.text
# Extract latest 'chromedriver' version from JSON data
version_number = resp.json()['channels']['Stable']['version']
return version_number

driver_filenames = {
'win': 'chromedriver.exe',
Expand All @@ -406,38 +408,39 @@ def get_download_path(self, version='latest'):

def get_download_url(self, version='latest'):
"""
Method for getting the download URL for the Google Chome driver binary.
Method for getting the download URL for the Google Chrome driver binary.
: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
: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.
"""
if version == 'latest':
version = self._get_latest_version_number()
# Just getting latest here, so no need to check for version
# if version == 'latest':
# version = self._get_latest_version_number()

LOGGER.debug('Detected OS: %sbit %s', self.bitness, self.os_name)

chrome_driver_objects = requests.get(self.chrome_driver_base_url + '/o').json()
# chromedriver only has 64 bit versions of mac and 32bit versions of windows. For now.
if self.os_name == 'win':
local_bitness = '32'
elif self.os_name == 'mac':
local_bitness = '64'
else:
local_bitness = self.bitness
chrome_driver_objects = requests.get(self.chrome_driver_base_url).json()
chromedriver_list = chrome_driver_objects['channels']['Stable']['downloads']['chromedriver']

matcher = r'{0}/.*{1}{2}.*'.format(version, self.os_name, local_bitness)
# Handle special case for 'win' to match the provided JSON structure
platform = "{}{}".format(self.os_name.lower(), self.bitness)

entry = [obj for obj in chrome_driver_objects['items'] if re.match(matcher, obj['name'])]
if not entry:
raise_runtime_error('Error, unable to find appropriate download for {0}{1}.'.format(self.os_name, self.bitness))
url = None
filename = None
print(chromedriver_list)
for entry in chromedriver_list:
print("Checking against platform:", entry['platform']) # Debugging statement
if entry['platform'] == platform:
url = entry['url']
filename = url.split("/")[-1]
break

url = entry[0]['mediaLink']
filename = os.path.basename(entry[0]['name'])
if not url:
raise ValueError("Could not find a matching chromedriver for the platform: {}".format(platform))
return (url, filename)


class OperaChromiumDriverManager(WebDriverManagerBase):
"""Class for downloading the Opera Chromium WebDriver.
"""
Expand Down Expand Up @@ -651,3 +654,4 @@ def get_download_url(self, version='latest'):
'edge': EdgeDriverManager,
'ie': IEDriverManager,
}

0 comments on commit f390489

Please sign in to comment.