Skip to content

Instantly share code, notes, and snippets.

@MarcusFelling
Created March 8, 2023 16:39
Show Gist options
  • Save MarcusFelling/9a513fe824a3aec9f875db3a41fff6c9 to your computer and use it in GitHub Desktop.
Save MarcusFelling/9a513fe824a3aec9f875db3a41fff6c9 to your computer and use it in GitHub Desktop.
import { test as setup } from '@playwright/test';
const authFile = '.auth/user.json';
setup('authenticate', async ({ browser }) => {
const page = await browser.newPage();
await page.goto('');
// Sign in using creds from env variables
const dialogPromise = page.waitForEvent('popup');
await page.getByText('LOGIN').click();
const dialog = await dialogPromise;
await dialog.getByPlaceholder('Email, phone, or Skype').fill(process.env.AADUSERNAME!);
await dialog.getByRole('button', { name: 'Next' }).click();
await dialog.getByPlaceholder('Password').fill(process.env.AADPASSWORD!);
await dialog.getByRole('button', { name: 'Sign in' }).click();
// Do not stay signed in
await dialog.getByRole('button', { name: 'No' }).click();
await page.context().storageState({ path: authFile });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment