From 4f83a5925942473c13a5e529c6fd47282c096b51 Mon Sep 17 00:00:00 2001 From: Anthony Hashemi Date: Thu, 2 Nov 2023 17:29:59 +0000 Subject: [PATCH] Add e2e tests for login view --- e2e_tests/test_login.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 e2e_tests/test_login.py 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."))