Skip to content

Instantly share code, notes, and snippets.

@corradin
Last active March 28, 2023 21:51
Show Gist options
  • Save corradin/7632ea89e37ba895e828a13445f1544d to your computer and use it in GitHub Desktop.
Save corradin/7632ea89e37ba895e828a13445f1544d to your computer and use it in GitHub Desktop.
import { chromium } from '@playwright/test';
import login from './utils/login';
const username = process.env.MEETUP_USERNAME ?? '';
const password = process.env.MEETUP_PASSWORD ?? '';
async function globalSetup(config: FullConfig): Promise<void> {
const { storageState } = config.projects[0].use;
// TODO: Remove headless after this has been tested
const browser = await chromium.launch({ headless: false });
const page = await browser.newPage();
await login(page, username, password);
await page.context().storageState({
path: storageState,
});
await browser.close();
}
export default globalSetup;
@tishdemsas
Copy link

@corradin It doesn't save the storageState to the designated path either which is making my test fail. Thanks for the help!

Global set up updated

import { chromium, FullConfig } from '@playwright/test';
import login from './tests/utils/login';

const username = process.env.PLAYWRIGHT_USERNAME ?? '';
const password = process.env.PLAYWRIGHT_PASSWORD ?? '';

async function globalSetup(config: FullConfig): Promise<void> {
  const { storageState } = config.projects[0].use;
  // TODO: Remove headless after this has been tested
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage();
  await login(page, username, password);
  await page.context().storageState({
    path: storageState as string,
  });
  console.log(storageState);
  await browser.close();
}

export default globalSetup;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment