|
1 | 1 | import { check } from "k6" |
2 | 2 | import { browser, Page } from "k6/browser" |
3 | | -import { randomIntBetween } from "https://jslib.k6.io/k6-utils/1.2.0/index.js" |
| 3 | +import { |
| 4 | + randomIntBetween, |
| 5 | + randomItem, |
| 6 | +} from "https://jslib.k6.io/k6-utils/1.2.0/index.js" |
4 | 7 | import { BROWSER_CONTEXT_OPTIONS, FRONTEND_BASE_URL } from "../config.ts" |
| 8 | +import { AuthCredential, credentials } from "../auth.ts" |
5 | 9 |
|
6 | 10 | async function home(page: Page) { |
7 | 11 | await page.goto(FRONTEND_BASE_URL) |
@@ -38,15 +42,47 @@ async function units(page: Page) { |
38 | 42 | await page.goto(`${FRONTEND_BASE_URL}/units`) |
39 | 43 | } |
40 | 44 |
|
| 45 | +async function login(page: Page) { |
| 46 | + const credential: AuthCredential = randomItem(credentials) |
| 47 | + |
| 48 | + if (!!credential) { |
| 49 | + log.debug("Skipping login because no credentials provided") |
| 50 | + return |
| 51 | + } |
| 52 | + |
| 53 | + const loginButton = page.getByTestId("login-button-desktop") |
| 54 | + await loginButton.first().click() |
| 55 | + |
| 56 | + await loginKeycloak(page) |
| 57 | + |
| 58 | + await page.waitForURL(/.*\/dashboard.*/) |
| 59 | +} |
| 60 | + |
| 61 | +async function loginKeycloak(page: Page, credential: AuthCredential) { |
| 62 | + await page.waitForURL( |
| 63 | + /https:\/sso(\-qa)?\.ol\.mit\.edu\/realms\/olapps\/protocol\/openid-connect\/auth.*/, |
| 64 | + ) |
| 65 | + |
| 66 | + const credentialnameInput = await page.locator("input#username") |
| 67 | + await credentialnameInput.type(user.email) |
| 68 | + await page.locator("button#kc-login").click() |
| 69 | + |
| 70 | + const passwordInput = await page.locator("input#password") |
| 71 | + await passwordInput.type(credential.password) |
| 72 | + await page.locator("button#kc-login").click() |
| 73 | +} |
| 74 | + |
41 | 75 | export async function testFrontend() { |
42 | 76 | const page = await browser.newPage(BROWSER_CONTEXT_OPTIONS) |
43 | 77 |
|
44 | 78 | try { |
| 79 | + // always home page first |
45 | 80 | await home(page) |
46 | 81 | await search(page) |
47 | 82 | await topics(page) |
48 | 83 | await departments(page) |
49 | 84 | await units(page) |
| 85 | + await login(page) |
50 | 86 | } finally { |
51 | 87 | await page.close() |
52 | 88 | } |
|
0 commit comments