| 
 | 1 | +import { test as base } from '@playwright/test';  | 
 | 2 | +import {  | 
 | 3 | +  SecretsManagerClient,  | 
 | 4 | +  GetSecretValueCommand,  | 
 | 5 | +} from "@aws-sdk/client-secrets-manager";  | 
 | 6 | + | 
 | 7 | +export const getSecretValue = async (  | 
 | 8 | +  secretId: string,  | 
 | 9 | +): Promise<Record<string, string | number | boolean> | null> => {  | 
 | 10 | +  const smClient = new SecretsManagerClient();  | 
 | 11 | +  const data = await smClient.send(  | 
 | 12 | +    new GetSecretValueCommand({ SecretId: secretId }),  | 
 | 13 | +  );  | 
 | 14 | +  if (!data.SecretString) {  | 
 | 15 | +    return null;  | 
 | 16 | +  }  | 
 | 17 | +  try {  | 
 | 18 | +    return JSON.parse(data.SecretString) as Record<  | 
 | 19 | +      string,  | 
 | 20 | +      string | number | boolean  | 
 | 21 | +    >;  | 
 | 22 | +  } catch {  | 
 | 23 | +    return null;  | 
 | 24 | +  }  | 
 | 25 | +};  | 
 | 26 | + | 
 | 27 | +async function getSecrets() {  | 
 | 28 | +  let response = { PLAYWRIGHT_USERNAME: '', PLAYWRIGHT_PASSWORD: '' }  | 
 | 29 | +  let keyData;  | 
 | 30 | +  if (!process.env.PLAYWRIGHT_USERNAME || !process.env.PLAYWRIGHT_PASSWORD || !process.env.JwtSigningKey) {  | 
 | 31 | +    keyData = await getSecretValue('infra-core-api-config')  | 
 | 32 | +  }  | 
 | 33 | +  response['PLAYWRIGHT_USERNAME'] = process.env.PLAYWRIGHT_USERNAME || keyData ? keyData['playwright_username'] : '';  | 
 | 34 | +  response['PLAYWRIGHT_PASSWORD'] = process.env.PLAYWRIGHT_PASSWORD || keyData ? keyData['playwright_password'] : '';  | 
 | 35 | +  return response;  | 
 | 36 | +}  | 
 | 37 | + | 
 | 38 | +const secrets = await getSecrets();  | 
 | 39 | + | 
 | 40 | +async function becomeUser(page) {  | 
 | 41 | +  await page.goto('https://manage.qa.acmuiuc.org/login');  | 
 | 42 | +  await page.getByRole('button', { name: 'Sign in with Illinois NetID' }).click();  | 
 | 43 | +  await page.getByPlaceholder('[email protected]').click();  | 
 | 44 | +  await page.getByPlaceholder('[email protected]').fill(secrets['PLAYWRIGHT_USERNAME']);  | 
 | 45 | +  await page.getByPlaceholder('[email protected]').press('Enter');  | 
 | 46 | +  await page.getByPlaceholder('Password').click();  | 
 | 47 | +  await page.getByPlaceholder('Password').fill(secrets['PLAYWRIGHT_PASSWORD']);  | 
 | 48 | +  await page.getByRole('button', { name: 'Sign in' }).click();  | 
 | 49 | +  await page.getByRole('button', { name: 'No' }).click();  | 
 | 50 | +}  | 
 | 51 | + | 
 | 52 | +export const test = base.extend<{ becomeUser: (page) => Promise<void> }>({  | 
 | 53 | +  becomeUser: async ({ }, use) => {  | 
 | 54 | +    use(becomeUser)  | 
 | 55 | +  },  | 
 | 56 | +});  | 
0 commit comments