|
| 1 | +import { expect, Page, APIRequestContext } from "@playwright/test"; |
| 2 | +import { config } from "../../general-config"; |
| 3 | + |
| 4 | +const SEL_UPORTAL_LOGIN = "#portalCASLoginLink"; |
| 5 | +const SEL_UPORTAL_LOGIN_USERNAME = "#username"; |
| 6 | +const SEL_UPORTAL_LOGIN_PASSWORD = "#password"; |
| 7 | +const SEL_UPORTAL_LOGIN_SUBMIT = ".btn-submit"; |
| 8 | + |
| 9 | +/* |
| 10 | + * Log into uPortal via an APIRequestContext |
| 11 | + */ |
| 12 | +export async function loginViaApi( |
| 13 | + request: APIRequestContext, |
| 14 | + username: string, |
| 15 | + password: string, |
| 16 | + displayname: string |
| 17 | +): Promise<void> { |
| 18 | + const url = `${config.url}Login?userName=${username}&password=${password}`; |
| 19 | + const response = await request.get(url); |
| 20 | + expect(response.status()).toEqual(200); |
| 21 | + const responseText = await response.text(); |
| 22 | + expect(responseText).toContain(displayname); |
| 23 | +} |
| 24 | + |
| 25 | +/* |
| 26 | + * Log into uPortal via the UX |
| 27 | + */ |
| 28 | +export async function loginViaPage( |
| 29 | + page: Page, |
| 30 | + username: string, |
| 31 | + password: string, |
| 32 | + displayname: string |
| 33 | +): Promise<void> { |
| 34 | + // Navigate to uPortal welcome page prior to login |
| 35 | + const landingPageUrl = `${config.url}f/welcome/normal/render.uP`; |
| 36 | + await page.goto(landingPageUrl); |
| 37 | + |
| 38 | + // Launch CAS Login via UX |
| 39 | + const uportalSignin = page.locator(SEL_UPORTAL_LOGIN); |
| 40 | + await expect(uportalSignin).toHaveText("Sign In"); |
| 41 | + await page.click(SEL_UPORTAL_LOGIN); |
| 42 | + |
| 43 | + // Fill in username and password, and submit |
| 44 | + await page.waitForSelector(SEL_UPORTAL_LOGIN_USERNAME); |
| 45 | + await page.fill(SEL_UPORTAL_LOGIN_USERNAME, username); |
| 46 | + await page.waitForSelector(SEL_UPORTAL_LOGIN_PASSWORD); |
| 47 | + await page.fill(SEL_UPORTAL_LOGIN_PASSWORD, password); |
| 48 | + await page.waitForSelector(SEL_UPORTAL_LOGIN_SUBMIT); |
| 49 | + await page.click(SEL_UPORTAL_LOGIN_SUBMIT); |
| 50 | + |
| 51 | + // Confirm uPortal logo |
| 52 | + const uportalLogo = page.locator("h1.portal-logo > a"); |
| 53 | + await expect(uportalLogo).toHaveText("uPortal"); |
| 54 | + |
| 55 | + // Confirm user is logged in |
| 56 | + const loggedInUserDisplay = page.locator("div.user-name"); |
| 57 | + await expect(loggedInUserDisplay).toHaveText( |
| 58 | + `You are signed in as ${displayname}` |
| 59 | + ); |
| 60 | +} |
0 commit comments