Skip to content

Commit

Permalink
Install a compatable version of chrome/chromedriver
Browse files Browse the repository at this point in the history
The chromedriver library updates more frequently than the chrome
distributed in ubuntu-latest, but these need to be the same version,
otherwise axe-core breaks.

As a workaround, try to install a version that matches whatever chrome
is on the path.

See also dequelabs/axe-core-npm#401 (comment)
  • Loading branch information
MatMoore committed Feb 26, 2024
1 parent 4eb5ead commit 755477f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ jobs:
id: fast-tests
run: poetry run pytest --cov -m 'not slow'

- name: Get Chromium version 🌐
run: |
CHROMIUM_VERSION=$(google-chrome --product-version)
echo "Chromium version: $CHROMIUM_VERSION"
echo "CHROMIUM_VERSION=$CHROMIUM_VERSION" >> $GITHUB_ENV
- name: Install chromedriver 🚗
run: |
npm install -g chromedriver@${CHROMIUM_VERSION%.*.*}
- name: run selenium tests
id: slow-tests
if: steps.fast-tests.outcome == 'success'
run: poetry run pytest -m 'slow'
run: poetry run pytest -m 'slow' --chromedriver-path=$(npm root -g)/chromedriver/bin/chromedriver

test_javascript:
runs-on: ubuntu-latest
Expand Down
18 changes: 13 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
fake = Faker()


def pytest_addoption(parser):
parser.addoption("--chromedriver-path", action="store")


@pytest.fixture
def chromedriver_path(request):
return request.config.getoption("--chromedriver-path")


def generate_page(page_size=20):
"""
Generate a fake search page
Expand All @@ -29,11 +38,10 @@ def generate_page(page_size=20):
results.append(
SearchResult(
id=fake.unique.name(),
result_type=choice(
(ResultType.DATA_PRODUCT, ResultType.TABLE)),
result_type=choice((ResultType.DATA_PRODUCT, ResultType.TABLE)),
name=fake.name(),
description=fake.paragraph(),
metadata={"search_summary":"a"},
metadata={"search_summary": "a"},
)
)
return results
Expand Down Expand Up @@ -85,8 +93,7 @@ def mock_search_response(mock_catalogue, total_results=0, page_results=()):


def mock_search_facets_response(mock_catalogue, domains):
mock_catalogue.search_facets.return_value = SearchFacets(
{"domains": domains})
mock_catalogue.search_facets.return_value = SearchFacets({"domains": domains})


@pytest.fixture
Expand All @@ -109,6 +116,7 @@ def valid_form():
def search_service(valid_form):
return SearchService(form=valid_form, page="1")


@pytest.fixture
def search_context(search_service):
return search_service.context
Expand Down
2 changes: 1 addition & 1 deletion tests/selenium/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pytest import CollectReport, StashKey
import datetime
from pathlib import Path
from typing import Any, Generator

import pytest
from pytest import CollectReport, StashKey
from selenium.webdriver import ChromeOptions
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.by import By
Expand Down
15 changes: 13 additions & 2 deletions tests/selenium/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import subprocess


def check_for_accessibility_issues(url):
command = ["npx", "@axe-core/cli", "-q", url]
def check_for_accessibility_issues(url, chromedriver_path=None):
command = ["npx", "@axe-core/cli"]

if chromedriver_path:
command.extend(["--chromedriver-path", chromedriver_path])

command.extend(
[
"-q",
url,
]
)

output = subprocess.run(command, capture_output=True, text=True)
assert output.returncode == 0, output.stdout
19 changes: 16 additions & 3 deletions tests/selenium/test_search_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@ class TestSearchWithoutJavascriptAndCss:
"""

@pytest.fixture(autouse=True)
def setup(self, live_server, selenium, home_page, search_page, details_page):
def setup(
self,
live_server,
selenium,
home_page,
search_page,
details_page,
chromedriver_path,
):
self.selenium = selenium
self.live_server_url = live_server.url
self.home_page = home_page
self.search_page = search_page
self.details_page = details_page
self.chromedriver_path = chromedriver_path

def test_browse_to_first_item(self):
"""
Expand Down Expand Up @@ -146,11 +155,15 @@ def test_clear_all_filters(self):

def test_automated_accessibility_home(self):
self.start_on_the_home_page()
check_for_accessibility_issues(self.selenium.current_url)
check_for_accessibility_issues(
self.selenium.current_url, chromedriver_path=self.chromedriver_path
)

def test_automated_accessibility_search(self):
self.start_on_the_search_page()
check_for_accessibility_issues(self.selenium.current_url)
check_for_accessibility_issues(
self.selenium.current_url, chromedriver_path=self.chromedriver_path
)

def start_on_the_home_page(self):
self.selenium.get(f"{self.live_server_url}")
Expand Down

0 comments on commit 755477f

Please sign in to comment.