Skip to content

Commit

Permalink
Pass chromedriver path
Browse files Browse the repository at this point in the history
  • Loading branch information
MatMoore committed Feb 26, 2024
1 parent 4c5778f commit b5ed0ec
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,10 @@ jobs:
- name: Install chromedriver 🚗
run: |
npm install -g chromedriver@$CHROMIUM_VERSION
- name: Install axe 🪓
run: |
npm install -g @axe-core/cli
- 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
9 changes: 4 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,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 +84,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 +107,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
11 changes: 10 additions & 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 All @@ -13,6 +13,15 @@
TMP_DIR = Path(__file__).parent / "../../tmp"


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


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


@pytest.fixture(scope="session")
def selenium(live_server) -> Generator[RemoteWebDriver, Any, None]:
options = ChromeOptions()
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 b5ed0ec

Please sign in to comment.