Skip to content

Commit

Permalink
Login before all e2e playwright tests that need authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyhashemi committed Nov 3, 2023
1 parent 4152a31 commit 4b0c933
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 36 deletions.
13 changes: 13 additions & 0 deletions e2e_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
24 changes: 15 additions & 9 deletions e2e_tests/test_poc_search.py
Original file line number Diff line number Diff line change
@@ -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)'
Expand Down
58 changes: 31 additions & 27 deletions e2e_tests/test_record_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,68 @@
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
Then the table should display the relevant metadata for the record such as
"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()

0 comments on commit 4b0c933

Please sign in to comment.