diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5f3441ea..a7c75df7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index cf1af01c..8fef0413 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/selenium/conftest.py b/tests/selenium/conftest.py index 13e03dab..7c7a5f18 100644 --- a/tests/selenium/conftest.py +++ b/tests/selenium/conftest.py @@ -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 diff --git a/tests/selenium/helpers.py b/tests/selenium/helpers.py index 21be4e61..48b10012 100644 --- a/tests/selenium/helpers.py +++ b/tests/selenium/helpers.py @@ -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 diff --git a/tests/selenium/test_search_scenarios.py b/tests/selenium/test_search_scenarios.py index e8d80d63..e7cb26a3 100644 --- a/tests/selenium/test_search_scenarios.py +++ b/tests/selenium/test_search_scenarios.py @@ -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): """ @@ -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}")