MCPcopy
hub / github.com/Agenta-AI/agenta / globalSetup

Function globalSetup

web/tests/playwright/global-setup.ts:23–160  ·  view source on GitHub ↗

* Runs before Playwright tests to automate authentication. * Handles both login and signup flows. * Stores authenticated state in a file to be reused by tests.

(config: FullConfig)

Source from the content-addressed store, hash-verified

21 * Stores authenticated state in a file to be reused by tests.
22 */
23async function globalSetup(config: FullConfig) {
24 // Automate authentication before Playwright tests
25 console.log("[global-setup] Starting global setup for authentication")
26
27 const project = config.projects.find((project) => project.name === process.env.PROJECT)
28 console.log(`[global-setup] Resolved project: ${process.env.PROJECT}`)
29 if (!project) {
30 throw new Error(`Project ${process.env.PROJECT} not found`)
31 }
32 const {baseURL, storageState} = project.use
33 const timeout = 60000
34 const inputDelay = 100
35
36 const {email, password} = createInitialUserState({
37 name: project.name,
38 })
39
40 console.log("[global-setup] Launching browser")
41 const browser = await chromium.launch()
42 const page = await browser.newPage()
43
44 console.log(`[global-setup] Navigating to auth page: ${baseURL}/auth`)
45 await page.goto(`${baseURL}/auth`)
46
47 console.log("[global-setup] Clearing local storage")
48
49 // @ts-ignore
50 await page.evaluate(() => window.localStorage.clear())
51
52 const testmail = getTestmailClient()
53 /**
54 * Fills OTP input fields on the page one digit at a time.
55 * @param otp - The one-time password string.
56 * @param delay - Delay in ms between typing each digit.
57 */
58 async function fillOTPDigits(otp: string, delay: number): Promise<void> {
59 console.log("[global-setup] Filling OTP digits")
60 const digits = otp.split("")
61 for (let i = 0; i < digits.length; i++) {
62 await typeWithDelay(page, `.ant-input:nth-child(${i + 1})`, digits[i], delay)
63 }
64 }
65
66 const timestamp = Date.now()
67 console.log(`[global-setup] Typing email: ${email}`)
68 await typeWithDelay(page, 'input[type="email"]', email)
69 const signinButton = await page.getByRole("button", {name: "Sign in"})
70
71 const hasSigninButton = await signinButton.isVisible()
72
73 if (hasSigninButton) {
74 // Password sign-in flow
75 if (!password) {
76 throw new Error("Password is required for password sign-in flow")
77 }
78
79 try {
80 console.log("[global-setup] Typing password")

Callers

nothing calls this directly

Calls 11

createInitialUserStateFunction · 0.90
getTestmailClientFunction · 0.90
typeWithDelayFunction · 0.90
waitForPathFunction · 0.90
clickButtonFunction · 0.90
waitForApiResponseFunction · 0.90
selectOptionFunction · 0.90
closeMethod · 0.80
waitForOTPMethod · 0.80
fillOTPDigitsFunction · 0.70
errorMethod · 0.45

Tested by

no test coverage detected