Skip to content

Commit

Permalink
Merge pull request #316 from nationalarchives/AYR-888/configure-brows…
Browse files Browse the repository at this point in the history
…er-e2e

Ayr 888/configure browser e2e
  • Loading branch information
anthonyhashemi authored Apr 8, 2024
2 parents 9dcf96e + 7d9a270 commit fb3089b
Show file tree
Hide file tree
Showing 91 changed files with 138 additions and 36 deletions.
52 changes: 45 additions & 7 deletions e2e_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,58 @@
import os

import pytest
from playwright.sync_api import Page
from playwright.sync_api import Page, Playwright


@pytest.fixture()
def aau_user_page(page) -> Page:
@pytest.fixture(params=["firefox", "chromium", "webkit"])
def aau_user_page(
request, playwright: Playwright, browser_context_args
) -> Page:
browser_type = request.param
if browser_type == "firefox":
browser = playwright.firefox
elif browser_type == "chromium":
browser = playwright.chromium
elif browser_type == "webkit":
browser = playwright.webkit
else:
raise ValueError(f"Unsupported browser type: {browser_type}")

browser_instance = browser.launch()

context = browser_instance.new_context(**browser_context_args)
page = context.new_page()
page.goto("/sign-in")
page.get_by_label("Email address").fill(
os.environ.get("AYR_AAU_USER_USERNAME")
)
page.get_by_label("Password").fill(os.environ.get("AYR_AAU_USER_PASSWORD"))
page.get_by_role("button", name="Sign in").click()
page.wait_for_url("/browse")
return page
yield page

context.close()
browser_instance.close()

@pytest.fixture()
def standard_user_page(page) -> Page:

@pytest.fixture(params=["firefox", "chromium", "webkit"])
def standard_user_page(
request, playwright: Playwright, browser_context_args
) -> Page:
browser_type = request.param
if browser_type == "firefox":
browser = playwright.firefox
elif browser_type == "chromium":
browser = playwright.chromium
elif browser_type == "webkit":
browser = playwright.webkit
else:
raise ValueError(f"Unsupported browser type: {browser_type}")

browser_instance = browser.launch()

context = browser_instance.new_context(**browser_context_args)
page = context.new_page()
page.goto("/sign-in")
page.get_by_label("Email address").fill(
os.environ.get("AYR_STANDARD_USER_USERNAME")
Expand All @@ -26,7 +61,10 @@ def standard_user_page(page) -> Page:
os.environ.get("AYR_STANDARD_USER_PASSWORD")
)
page.get_by_role("button", name="Sign in").click()
return page
yield page

context.close()
browser_instance.close()


@pytest.fixture(scope="session")
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions e2e_tests/test_browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ def test_browse_date_filter_validation_date_from(self, aau_user_page: Page):
aau_user_page.locator("#date_from_year").fill("2024")
aau_user_page.get_by_role("button", name="Apply filters").click()

aau_user_page.wait_for_selector(".govuk-error-message")

assert aau_user_page.get_by_text(
"‘Date from’ must be in the past"
).is_visible()
Expand All @@ -204,6 +206,8 @@ def test_browse_date_filter_validation_to_date(self, aau_user_page: Page):
aau_user_page.locator("#date_to_year").fill("2024")
aau_user_page.get_by_role("button", name="Apply filters").click()

aau_user_page.wait_for_selector(".govuk-error-message")

assert aau_user_page.get_by_text(
"‘Date to’ must be in the past"
).is_visible()
Expand All @@ -220,6 +224,8 @@ def test_browse_date_filter_validation_date_from_and_to_date(
aau_user_page.locator("#date_to_year").fill("2022")
aau_user_page.get_by_role("button", name="Apply filters").click()

aau_user_page.wait_for_selector(".govuk-error-message")

assert aau_user_page.get_by_text(
"‘Date from’ must be the same as or before ‘31/12/2022’"
).is_visible()
Expand Down
40 changes: 27 additions & 13 deletions e2e_tests/test_browse_consignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def test_browse_consignment_no_pagination(self, standard_user_page: Page):

standard_user_page.get_by_role("button", name="Apply filters").click()

next_button = standard_user_page.locator(".govuk-pagination__next a")

assert not standard_user_page.get_by_label("Page 1").is_visible()
assert not standard_user_page.get_by_label("Page 2").is_visible()
assert not standard_user_page.get_by_role(
"link", name="Nextpage"
).is_visible()
assert not next_button.is_visible()

def test_browse_consignment_has_pagination_with_next_page(
self, standard_user_page: Page
Expand All @@ -86,28 +86,32 @@ def test_browse_consignment_has_pagination_with_next_page(

standard_user_page.get_by_role("button", name="Apply filters").click()

standard_user_page.wait_for_selector(".govuk-pagination")
next_button = standard_user_page.locator(".govuk-pagination__next a")
assert next_button.is_visible()
assert standard_user_page.get_by_label("Page 1").is_visible()
assert standard_user_page.get_by_label("Page 2").is_visible()
assert standard_user_page.get_by_role(
"link", name="Nextpage"
).is_visible()

def test_browse_consignment_has_pagination_with_previous_and_next_page(
self, standard_user_page: Page
):
standard_user_page.goto(f"{self.route_url}/{self.consignment_id}")

standard_user_page.get_by_role("link", name="Nextpage").click()
standard_user_page.wait_for_selector(".govuk-pagination")

assert standard_user_page.get_by_role(
"link", name="Previouspage"
).is_visible()
previous_button = standard_user_page.locator(
".govuk-pagination__prev a"
)
next_button = standard_user_page.locator(".govuk-pagination__next a")
next_button.click()

standard_user_page.wait_for_selector(".govuk-pagination")

assert previous_button.is_visible()
assert next_button.is_visible()
assert standard_user_page.get_by_label("Page 1").is_visible()
assert standard_user_page.get_by_label("Page 2").is_visible()
assert standard_user_page.get_by_label("Page 3").is_visible()
assert standard_user_page.get_by_role(
"link", name="Nextpage"
).is_visible()

def test_browse_consignment_filter_functionality_with_query_string_parameters(
self, standard_user_page: Page
Expand Down Expand Up @@ -262,6 +266,8 @@ def test_browse_consignment_date_validation_with_empty_date_fields_and_date_filt
"button", name="Apply", exact=True
).click()

standard_user_page.wait_for_selector(".govuk-error-message")

assert standard_user_page.get_by_text(
"Please enter value(s) in ‘Date from’ or ‘Date to’ field"
).is_visible()
Expand All @@ -277,6 +283,8 @@ def test_browse_consignment_date_validation_with_date_fields_and_no_date_filter_
"button", name="Apply", exact=True
).click()

standard_user_page.wait_for_selector(".govuk-error-message")

assert standard_user_page.get_by_text(
"Select either ‘Date of record’ or ‘Record opening date’"
).is_visible()
Expand All @@ -293,6 +301,8 @@ def test_browse_consignment_date_filter_validation_date_from(
standard_user_page.locator("#date_from_year").fill("2024")
standard_user_page.get_by_role("button", name="Apply filters").click()

standard_user_page.wait_for_selector(".govuk-error-message")

assert standard_user_page.get_by_text(
"‘Date from’ must be in the past"
).is_visible()
Expand All @@ -309,6 +319,8 @@ def test_browse_consignment_date_filter_validation_to_date(
standard_user_page.locator("#date_to_year").fill("2024")
standard_user_page.get_by_role("button", name="Apply filters").click()

standard_user_page.wait_for_selector(".govuk-error-message")

assert standard_user_page.get_by_text(
"‘Date to’ must be in the past"
).is_visible()
Expand All @@ -328,6 +340,8 @@ def test_browse_consignment_date_filter_validation_date_from_and_to_date(
standard_user_page.locator("#date_to_year").fill("2022")
standard_user_page.get_by_role("button", name="Apply filters").click()

standard_user_page.wait_for_selector(".govuk-error-message")

assert standard_user_page.get_by_text(
"‘Date from’ must be the same as or before ‘31/12/2022’"
).is_visible()
Expand Down
10 changes: 10 additions & 0 deletions e2e_tests/test_browse_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def test_browse_series_sort_functionality_by_records_held_in_consignment_descend
"button", name="Apply", exact=True
).click()

standard_user_page.wait_for_selector("#tbl_result")

header_rows = standard_user_page.locator(
"#tbl_result tr:visible"
).evaluate_all(
Expand Down Expand Up @@ -138,6 +140,8 @@ def test_browse_series_filter_functionality_with_date_filter(
standard_user_page.locator("#date_from_year").fill("2024")
standard_user_page.get_by_role("button", name="Apply filters").click()

standard_user_page.wait_for_selector("#tbl_result")

header_rows = standard_user_page.locator(
"#tbl_result tr:visible"
).evaluate_all(
Expand Down Expand Up @@ -169,6 +173,8 @@ def test_browse_series_date_filter_validation_date_from(
standard_user_page.locator("#date_from_year").fill("2024")
standard_user_page.get_by_role("button", name="Apply filters").click()

standard_user_page.wait_for_selector(".govuk-error-message")

assert standard_user_page.get_by_text(
"‘Date from’ must be in the past"
).is_visible()
Expand All @@ -182,6 +188,8 @@ def test_browse_series_date_filter_validation_to_date(
standard_user_page.locator("#date_to_year").fill("2024")
standard_user_page.get_by_role("button", name="Apply filters").click()

standard_user_page.wait_for_selector(".govuk-error-message")

assert standard_user_page.get_by_text(
"‘Date to’ must be in the past"
).is_visible()
Expand All @@ -198,6 +206,8 @@ def test_browse_series_date_filter_validation_date_from_and_to_date(
standard_user_page.locator("#date_to_year").fill("2022")
standard_user_page.get_by_role("button", name="Apply filters").click()

standard_user_page.wait_for_selector(".govuk-error-message")

assert standard_user_page.get_by_text(
"‘Date from’ must be the same as or before ‘31/12/2022’"
).is_visible()
Expand Down
20 changes: 17 additions & 3 deletions e2e_tests/test_browse_transferring_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def test_browse_transferring_body_no_pagination(

standard_user_page.get_by_role("button", name="Apply filters").click()

next_button = standard_user_page.locator(".govuk-pagination__next a")

assert not standard_user_page.get_by_label("Page 1").is_visible()
assert not standard_user_page.get_by_label("Page 2").is_visible()
assert not standard_user_page.get_by_role(
"link", name="Nextpage"
).is_visible()
assert not next_button.is_visible()

def test_browse_transferring_body_filter_functionality_with_query_string_parameters(
self, standard_user_page: Page
Expand Down Expand Up @@ -127,6 +127,8 @@ def test_browse_transferring_body_sort_functionality_by_series_descending(
"button", name="Apply", exact=True
).click()

standard_user_page.wait_for_selector("#tbl_result")

header_rows = standard_user_page.locator(
"#tbl_result tr:visible"
).evaluate_all(
Expand Down Expand Up @@ -162,6 +164,8 @@ def test_browse_transferring_body_filter_functionality_with_series_filter(
"button", name="Apply", exact=True
).click()

standard_user_page.wait_for_selector("#tbl_result")

header_rows = standard_user_page.locator(
"#tbl_result tr:visible"
).evaluate_all(
Expand Down Expand Up @@ -194,6 +198,8 @@ def test_browse_transferring_body_filter_functionality_with_series_filter_wildca
standard_user_page.locator("#series_filter").fill("1")
standard_user_page.get_by_role("button", name="Apply filters").click()

standard_user_page.wait_for_selector("#tbl_result")

header_rows = standard_user_page.locator(
"#tbl_result tr:visible"
).evaluate_all(
Expand Down Expand Up @@ -228,6 +234,8 @@ def test_browse_transferring_body_filter_functionality_with_date_filter(
standard_user_page.locator("#date_from_year").fill("2024")
standard_user_page.get_by_role("button", name="Apply filters").click()

standard_user_page.wait_for_selector("#tbl_result")

header_rows = standard_user_page.locator(
"#tbl_result tr:visible"
).evaluate_all(
Expand Down Expand Up @@ -262,6 +270,8 @@ def test_browse_transferring_body_date_filter_validation_date_from(
standard_user_page.locator("#date_from_year").fill("2024")
standard_user_page.get_by_role("button", name="Apply filters").click()

standard_user_page.wait_for_selector(".govuk-error-message")

assert standard_user_page.get_by_text(
"‘Date from’ must be in the past"
).is_visible()
Expand All @@ -275,6 +285,8 @@ def test_browse_transferring_body_date_filter_validation_to_date(
standard_user_page.locator("#date_to_year").fill("2024")
standard_user_page.get_by_role("button", name="Apply filters").click()

standard_user_page.wait_for_selector(".govuk-error-message")

assert standard_user_page.get_by_text(
"‘Date to’ must be in the past"
).is_visible()
Expand All @@ -291,6 +303,8 @@ def test_browse_transferring_body_date_filter_validation_date_from_and_to_date(
standard_user_page.locator("#date_to_year").fill("2022")
standard_user_page.get_by_role("button", name="Apply filters").click()

standard_user_page.wait_for_selector(".govuk-error-message")

assert standard_user_page.get_by_text(
"‘Date from’ must be the same as or before ‘31/12/2022’"
).is_visible()
Expand Down
Loading

0 comments on commit fb3089b

Please sign in to comment.