2022-03-26 00:39:38 +00:00
|
|
|
import { loadEnvConfig } from "@next/env";
|
2021-12-15 16:25:49 +00:00
|
|
|
import { Browser, chromium } from "@playwright/test";
|
2022-01-06 17:28:31 +00:00
|
|
|
import fs from "fs";
|
2021-12-15 16:25:49 +00:00
|
|
|
|
|
|
|
async function loginAsUser(username: string, browser: Browser) {
|
2022-01-06 17:28:31 +00:00
|
|
|
// Skip is file exists
|
|
|
|
if (fs.existsSync(`playwright/artifacts/${username}StorageState.json`)) return;
|
2021-12-15 16:25:49 +00:00
|
|
|
const page = await browser.newPage();
|
2021-12-17 16:58:23 +00:00
|
|
|
await page.goto(`${process.env.PLAYWRIGHT_TEST_BASE_URL}/auth/login`);
|
2021-12-15 16:25:49 +00:00
|
|
|
// Click input[name="email"]
|
|
|
|
await page.click('input[name="email"]');
|
|
|
|
// Fill input[name="email"]
|
|
|
|
await page.fill('input[name="email"]', `${username}@example.com`);
|
|
|
|
// Press Tab
|
|
|
|
await page.press('input[name="email"]', "Tab");
|
|
|
|
// Fill input[name="password"]
|
|
|
|
await page.fill('input[name="password"]', username);
|
|
|
|
// Press Enter
|
|
|
|
await page.press('input[name="password"]', "Enter");
|
|
|
|
await page.waitForSelector(
|
|
|
|
username === "onboarding" ? "[data-testid=onboarding]" : "[data-testid=dashboard-shell]"
|
|
|
|
);
|
|
|
|
// Save signed-in state to '${username}StorageState.json'.
|
|
|
|
await page.context().storageState({ path: `playwright/artifacts/${username}StorageState.json` });
|
|
|
|
await page.context().close();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function globalSetup(/* config: FullConfig */) {
|
2022-03-26 00:39:38 +00:00
|
|
|
loadEnvConfig(process.env.PWD);
|
2021-12-15 16:25:49 +00:00
|
|
|
const browser = await chromium.launch();
|
|
|
|
await loginAsUser("onboarding", browser);
|
|
|
|
// await loginAsUser("free-first-hidden", browser);
|
|
|
|
await loginAsUser("pro", browser);
|
2022-01-03 22:50:59 +00:00
|
|
|
await loginAsUser("trial", browser);
|
2021-12-15 16:25:49 +00:00
|
|
|
await loginAsUser("free", browser);
|
|
|
|
// await loginAsUser("usa", browser);
|
|
|
|
// await loginAsUser("teamfree", browser);
|
2022-01-26 16:56:22 +00:00
|
|
|
await loginAsUser("teampro", browser);
|
2021-12-15 16:25:49 +00:00
|
|
|
await browser.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
export default globalSetup;
|