mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-05 10:36:06 -06:00
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com> Co-authored-by: Matthias Nannt <mail@matthiasnannt.com> Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com> Co-authored-by: Victor Santos <victor@formbricks.com> Co-authored-by: victorvhs017 <115753265+victorvhs017@users.noreply.github.com>
28 lines
1010 B
TypeScript
28 lines
1010 B
TypeScript
import { Page } from "@playwright/test";
|
|
import { UsersFixture } from "../fixtures/users";
|
|
|
|
export async function loginAndGetApiKey(page: Page, users: UsersFixture) {
|
|
const user = await users.create();
|
|
await user.login();
|
|
|
|
await page.waitForURL(/\/environments\/[^/]+\/surveys/);
|
|
|
|
const environmentId =
|
|
/\/environments\/([^/]+)\/surveys/.exec(page.url())?.[1] ??
|
|
(() => {
|
|
throw new Error("Unable to parse environmentId from URL");
|
|
})();
|
|
|
|
await page.goto(`/environments/${environmentId}/project/api-keys`);
|
|
|
|
await page.getByRole("button", { name: "Add Production API Key" }).isVisible();
|
|
await page.getByRole("button", { name: "Add Production API Key" }).click();
|
|
await page.getByPlaceholder("e.g. GitHub, PostHog, Slack").fill("E2E Test API Key");
|
|
await page.getByRole("button", { name: "Add API Key" }).click();
|
|
await page.locator(".copyApiKeyIcon").click();
|
|
|
|
const apiKey = await page.evaluate("navigator.clipboard.readText()");
|
|
|
|
return { environmentId, apiKey };
|
|
}
|