You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey guys, I noticed you dont have much on playwright documentation so I thought Id share my setup to help others:
auth.setup.ts
import{testassetup}from'@playwright/test';import{config}from'../config';importClerkfrom'@clerk/clerk-js';typeClerkType=typeofClerk;constauthFile='playwright/.auth/user.json';setup('authenticate',async({ page })=>{awaitpage.goto(config.HOST)awaitpage.waitForLoadState('networkidle')constdata={strategy: 'password',identifier: process.env.PLAYWRIGHT_E2E_USER_EMAIL||'',password: process.env.PLAYWRIGHT_E2E_USER_PASSWORD||'',}awaitpage.evaluate(asyncdata=>{// wait function as promiseconstwait=(ms: number)=>newPromise(resolve=>setTimeout(resolve,ms));constwdw=windowasWindow&typeofglobalThis&{Clerk: ClerkType};/** clear the cookies */document.cookie.split(";").forEach(function(c){document.cookie=c.replace(/^ +/,"").replace(/=.*/,"=;expires="+newDate().toUTCString()+";path=/");});constclerkIsReady=(window: Window&typeofglobalThis&{Clerk: ClerkType})=>{returnwdw.Clerk&&wdw.Clerk.isReady();}while(!clerkIsReady(wdw)){awaitwait(100);}constres=awaitwdw.Clerk.client?.signIn.create(data);if(!res){thrownewError(`Failed to sign in`);}awaitwdw.Clerk.setActive({session: res.createdSessionId,});},data);awaitpage.context().storageState({path: authFile});});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey guys, I noticed you dont have much on playwright documentation so I thought Id share my setup to help others:
auth.setup.ts
playwright.config.ts
Beta Was this translation helpful? Give feedback.
All reactions