diff --git a/e2e_tests/test_login.py b/e2e_tests/test_login.py new file mode 100644 index 00000000..8c01132a --- /dev/null +++ b/e2e_tests/test_login.py @@ -0,0 +1,31 @@ +import os + +from playwright.sync_api import Page, expect + + +def test_login_succeeds_when_valid_credentials(page: Page): + """ + Given a user is on the login page, + When they provide valid credentials and click the "Sign in" button, + Then they should see a success message indicating they are logged in with access to AYR. + And they should be on the '/poc-search-view' 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() + expect(page).to_have_url("/poc-search-view") + expect(page.get_by_text("TNA User is logged in and has access to AYR.")) + + +def test_login_fails_when_invalid_credentials(page: Page): + """ + Given a user is on the login page, + When they provide invalid credentials and click the "Sign in" button, + Then they should see an error message indicating the provided credentials are invalid. + """ + page.goto("/login") + page.get_by_label("Email address").fill("bad") + page.get_by_label("Password").fill("credentials") + page.get_by_role("button", name="Sign in").click() + expect(page.get_by_text("Invalid username or password."))