diff --git a/e2e_tests/conftest.py b/e2e_tests/conftest.py new file mode 100644 index 00000000..514229eb --- /dev/null +++ b/e2e_tests/conftest.py @@ -0,0 +1,13 @@ +import os + +import pytest + + +@pytest.fixture() +def authenticated_page(page): + page.goto("/login") + page.get_by_label("Email address").fill(os.environ.get("AYR_TEST_USERNAME")) + page.get_by_label("Password").fill(os.environ.get("AYR_TEST_PASSWORD")) + page.get_by_role("button", name="Sign in").click() + page.wait_for_url("/poc-search-view") + return page diff --git a/e2e_tests/test_poc_search.py b/e2e_tests/test_poc_search.py index 81aff4fc..5df8f79d 100644 --- a/e2e_tests/test_poc_search.py +++ b/e2e_tests/test_poc_search.py @@ -1,25 +1,31 @@ from playwright.sync_api import Page, expect -def test_poc_search_end_to_end(page: Page): +def test_poc_search_end_to_end(authenticated_page: Page): """ Given a user on the search page When they interact with the search form and submit a query Then the table should contain the expected headers and entries. """ - page.goto("/poc-search-view") + authenticated_page.goto("/poc-search-view") - expect(page.get_by_text("Search design PoC")).to_be_visible() - expect(page.locator("text=Search for digital records")).to_be_visible() + expect(authenticated_page.get_by_text("Search design PoC")).to_be_visible() + expect( + authenticated_page.locator("text=Search for digital records") + ).to_be_visible() # Interact with the search form and submit a query - page.fill("#searchInput", "Test description") - expect(page.locator("#searchInput")).to_have_value("Test description") - page.get_by_role("button").get_by_text("Search").click() + authenticated_page.fill("#searchInput", "Test description") + expect(authenticated_page.locator("#searchInput")).to_have_value( + "Test description" + ) + authenticated_page.get_by_role("button").get_by_text("Search").click() - expect(page.locator("#searchInput")).not_to_have_value("Test description") + expect(authenticated_page.locator("#searchInput")).not_to_have_value( + "Test description" + ) - table = page.locator("table") + table = authenticated_page.locator("table") # Use JavaScript to extract the text of header elements (th) within the table header_texts = table.evaluate( '(table) => Array.from(table.querySelectorAll("th")).map(th => th.textContent)' diff --git a/e2e_tests/test_record_metadata.py b/e2e_tests/test_record_metadata.py index 42af0d33..d73818e4 100644 --- a/e2e_tests/test_record_metadata.py +++ b/e2e_tests/test_record_metadata.py @@ -4,47 +4,47 @@ from playwright.sync_api import Page, expect -def test_page_title_and_header(page: Page): +def test_page_title_and_header(authenticated_page: Page): """ Given the user accesses AYR When the user loads the record page Then the AYR record title should be displayed """ - page.goto("/record") - expect(page).to_have_title( + authenticated_page.goto("/record") + expect(authenticated_page).to_have_title( re.compile("Page not found – AYR - Access Your Records – GOV.UK") ) - expect(page.get_by_text("Page not found")).to_be_visible() + expect(authenticated_page.get_by_text("Page not found")).to_be_visible() -def test_invalid_record(page: Page): +def test_invalid_record(authenticated_page: Page): """ Given the user accesses AYR When the user loads an invalid record page Then the AYR 404 page should be displayed """ - page.goto("/record") - expect(page.get_by_text("Page not found")).to_be_visible() + authenticated_page.goto("/record") + expect(authenticated_page.get_by_text("Page not found")).to_be_visible() -def test_back_link(page: Page): +def test_back_link(authenticated_page: Page): """ Given a user is on the record page When the user selects the back button / breadcrumb Then the user should be navigated back to the the results page """ - page.goto("/poc-search-view") - page.locator("#searchInput").click() - page.locator("#searchInput").fill("public record") - page.get_by_role("button", name="Search").click() - expect(page.get_by_text("records found")).to_be_visible() - page.get_by_role("link", name="file-b2.txt").click() - page.get_by_role("link", name="Back", exact=True).click() - page.wait_for_url("/poc-search-view") - page.close() + authenticated_page.goto("/poc-search-view") + authenticated_page.locator("#searchInput").click() + authenticated_page.locator("#searchInput").fill("public record") + authenticated_page.get_by_role("button", name="Search").click() + expect(authenticated_page.get_by_text("records found")).to_be_visible() + authenticated_page.get_by_role("link", name="file-b2.txt").click() + authenticated_page.get_by_role("link", name="Back", exact=True).click() + authenticated_page.wait_for_url("/poc-search-view") + authenticated_page.close() -def test_searched_record_metadata(page: Page): +def test_searched_record_metadata(authenticated_page: Page): """ Given the user has clicked on a result displayed on the search page with results displayed. When the user is on the record page @@ -52,16 +52,20 @@ def test_searched_record_metadata(page: Page): "Source organisation" and "Consignment ID," """ time.sleep(10) - page.goto("/poc-search-view") - page.locator("#searchInput").click() - page.locator("#searchInput").fill("public record") - page.get_by_role("button", name="Search").click() - expect(page.get_by_text("records found")).to_be_visible() - page.get_by_role("link", name="file-b2.txt").click() + authenticated_page.goto("/poc-search-view") + authenticated_page.locator("#searchInput").click() + authenticated_page.locator("#searchInput").fill("public record") + authenticated_page.get_by_role("button", name="Search").click() + expect(authenticated_page.get_by_text("records found")).to_be_visible() + authenticated_page.get_by_role("link", name="file-b2.txt").click() # Verify if the expected metadata is visible on the record page - assert page.locator("dt:has-text('Source organisation') + dd").is_visible() - assert page.locator("dt:has-text('Consignment ID') + dd").is_visible() + assert authenticated_page.locator( + "dt:has-text('Source organisation') + dd" + ).is_visible() + assert authenticated_page.locator( + "dt:has-text('Consignment ID') + dd" + ).is_visible() # Close the page - page.close() + authenticated_page.close()