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 authored and mitchdawson1982 committed Feb 26, 2024
1 parent 2b1fd7d commit 369f453
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 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
14 changes: 9 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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, result_type: ResultType = None):
"""
Generate a fake search page
Expand All @@ -35,11 +44,6 @@ def generate_page(page_size=20, result_type: ResultType = None):
SearchResult(
id=fake.unique.name(),
result_type=choice((ResultType.DATA_PRODUCT, ResultType.TABLE)),
result_type=(
choice((ResultType.DATA_PRODUCT, ResultType.TABLE))
if result_type is None
else result_type
),
name=fake.name(),
description=fake.paragraph(),
metadata={"search_summary": "a"},
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
17 changes: 14 additions & 3 deletions tests/selenium/test_search_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ class TestSearchWithoutJavascriptAndCss:

@pytest.fixture(autouse=True)
def setup(
self, live_server, selenium, home_page, search_page, details_data_product_page
self,
live_server,
selenium,
home_page,
search_page,
details_data_product_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_data_product_page = details_data_product_page
self.chromedriver_path = chromedriver_path

def test_browse_to_first_item_data_product(self, mock_catalogue):
"""
Expand Down Expand Up @@ -160,11 +167,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 test_search_to_data_product_details(self, mock_catalogue):
"""
Expand Down

0 comments on commit 369f453

Please sign in to comment.