Skip to content

chrome: check for binary in known locations #29

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

Merged
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
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Mark the file as binary, so that Git won't not convert the line endings.
# Otherwise, the file becomes unreadable for bash inside Docker (on Windows platforms).
entrypoint.sh -text

13 changes: 1 addition & 12 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,7 @@ jobs:
shell: powershell

- name: Check Chrome Version
run: '& "C:\Program Files\Google\Chrome\Application\chrome.exe" --version'
shell: powershell

- name: Add Chrome to PATH
run: |
$chromePath = "C:\Program Files\Google\Chrome\Application"
echo "Adding $chromePath to PATH"
echo "$chromePath" | Out-File -Append -Encoding utf8 $env:GITHUB_PATH
shell: powershell

- name: Verify Chrome Installation
run: chrome --version
run: '(Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo'
shell: powershell

- name: Upgrade pip
Expand Down
23 changes: 21 additions & 2 deletions html2print/html2print.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,18 @@ def _download_chromedriver(
path_to_cached_chrome_driver: str,
) -> str:
url = "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
response = ChromeDriverManager.send_http_get_request(url).json()
response = ChromeDriverManager.send_http_get_request(url)
if response is None:
raise RuntimeError(
"Could not download known-good-versions-with-downloads.json"
)

response = response.json()
if response is None:
raise RuntimeError(
"Could not parse known-good-versions-with-downloads.json"
)
assert isinstance(response, dict)

matching_versions = [
item
Expand All @@ -118,7 +129,7 @@ def _download_chromedriver(
]

if not matching_versions:
raise Exception(
raise RuntimeError(
f"No compatible ChromeDriver found for Chrome version {chrome_major_version}"
)

Expand All @@ -142,6 +153,11 @@ def _download_chromedriver(
)
response = ChromeDriverManager.send_http_get_request(driver_url)

if response is None:
raise RuntimeError(
f"Could not download ChromeDriver from {driver_url}"
)

Path(path_to_driver_cache_dir).mkdir(parents=True, exist_ok=True)
zip_path = os.path.join(path_to_driver_cache_dir, "chromedriver.zip")
print( # noqa: T201
Expand Down Expand Up @@ -179,6 +195,9 @@ def send_http_get_request(url: str) -> Response:
f"html2print: "
f"failed to get response for URL: {url} with error: {last_error}"
)
raise RuntimeError(
f"GET request failed after 3 attempts: {url}"
) from last_error

@staticmethod
def get_chrome_version() -> Optional[str]:
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ config.suffixes = ['.itest', '.c']
config.is_windows = lit_config.isWindows
if not lit_config.isWindows:
config.available_features.add('PLATFORM_IS_NOT_WINDOWS')

# In Linux CI, $HOME is required for Chrome as it needs to access things in ~/.local
config.environment['HOME'] = os.environ.get('HOME', '/tmp')

# In Windows CI, %ProgramW6432% is required for Selenium to properly detect browsers
config.environment['ProgramW6432'] = os.environ.get('ProgramW6432', '')